Cleanup errorOut resp restart tests

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
Jessica Frazelle 2014-10-14 14:18:55 -07:00
parent 6f1c8ff4c4
commit 9f52d8e6e7
1 changed files with 45 additions and 19 deletions

View File

@ -10,29 +10,37 @@ import (
func TestRestartStoppedContainer(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", "foobar")
out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
cleanedContainerID := stripTrailingCharacters(out)
runCmd = exec.Command(dockerBinary, "wait", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
if out != "foobar\n" {
t.Errorf("container should've printed 'foobar'")
}
runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
if out != "foobar\nfoobar\n" {
t.Errorf("container should've printed 'foobar' twice")
@ -46,7 +54,9 @@ func TestRestartStoppedContainer(t *testing.T) {
func TestRestartRunningContainer(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "echo foobar && sleep 30 && echo 'should not print this'")
out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
cleanedContainerID := stripTrailingCharacters(out)
@ -54,19 +64,24 @@ func TestRestartRunningContainer(t *testing.T) {
runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
if out != "foobar\n" {
t.Errorf("container should've printed 'foobar'")
}
runCmd = exec.Command(dockerBinary, "restart", "-t", "1", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "logs", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
time.Sleep(1 * time.Second)
@ -83,13 +98,17 @@ func TestRestartRunningContainer(t *testing.T) {
func TestRestartWithVolumes(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "-v", "/test", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
cleanedContainerID := stripTrailingCharacters(out)
runCmd = exec.Command(dockerBinary, "inspect", "--format", "{{ len .Volumes }}", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
if out = strings.Trim(out, " \n\r"); out != "1" {
t.Errorf("expect 1 volume received %s", out)
@ -97,15 +116,20 @@ func TestRestartWithVolumes(t *testing.T) {
runCmd = exec.Command(dockerBinary, "inspect", "--format", "{{ .Volumes }}", cleanedContainerID)
volumes, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, volumes)
if err != nil {
t.Fatal(volumes, err)
}
runCmd = exec.Command(dockerBinary, "restart", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "inspect", "--format", "{{ len .Volumes }}", cleanedContainerID)
out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out)
if err != nil {
t.Fatal(out, err)
}
if out = strings.Trim(out, " \n\r"); out != "1" {
t.Errorf("expect 1 volume after restart received %s", out)
@ -113,7 +137,9 @@ func TestRestartWithVolumes(t *testing.T) {
runCmd = exec.Command(dockerBinary, "inspect", "--format", "{{ .Volumes }}", cleanedContainerID)
volumesAfterRestart, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, volumesAfterRestart)
if err != nil {
t.Fatal(volumesAfterRestart, err)
}
if volumes != volumesAfterRestart {
volumes = strings.Trim(volumes, " \n\r")