Cleanup errorOut resp in ps 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 13:04:37 -07:00
parent ef787eb824
commit d33f2bdb11

View file

@ -10,34 +10,45 @@ import (
func TestPsListContainers(t *testing.T) { func TestPsListContainers(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err := runCommandWithOutput(runCmd) out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
firstID := stripTrailingCharacters(out) firstID := stripTrailingCharacters(out)
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top") runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
secondID := stripTrailingCharacters(out) secondID := stripTrailingCharacters(out)
// not long running // not long running
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "true") runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
thirdID := stripTrailingCharacters(out) thirdID := stripTrailingCharacters(out)
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top") runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "top")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
fourthID := stripTrailingCharacters(out) fourthID := stripTrailingCharacters(out)
// make sure third one is not running // make sure third one is not running
runCmd = exec.Command(dockerBinary, "wait", thirdID) runCmd = exec.Command(dockerBinary, "wait", thirdID)
out, _, err = runCommandWithOutput(runCmd) if out, _, err = runCommandWithOutput(runCmd); err != nil {
errorOut(err, t, out) t.Fatal(out, err)
}
// all // all
runCmd = exec.Command(dockerBinary, "ps", "-a") runCmd = exec.Command(dockerBinary, "ps", "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) { if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -46,7 +57,9 @@ func TestPsListContainers(t *testing.T) {
// running // running
runCmd = exec.Command(dockerBinary, "ps") runCmd = exec.Command(dockerBinary, "ps")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, []string{fourthID, secondID, firstID}) { if !assertContainerList(out, []string{fourthID, secondID, firstID}) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -57,7 +70,9 @@ func TestPsListContainers(t *testing.T) {
// limit // limit
runCmd = exec.Command(dockerBinary, "ps", "-n=2", "-a") runCmd = exec.Command(dockerBinary, "ps", "-n=2", "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected := []string{fourthID, thirdID} expected := []string{fourthID, thirdID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -66,7 +81,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "-n=2") runCmd = exec.Command(dockerBinary, "ps", "-n=2")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -75,7 +92,9 @@ func TestPsListContainers(t *testing.T) {
// since // since
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-a") runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected = []string{fourthID, thirdID, secondID} expected = []string{fourthID, thirdID, secondID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -84,7 +103,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID) runCmd = exec.Command(dockerBinary, "ps", "--since", firstID)
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -93,7 +114,9 @@ func TestPsListContainers(t *testing.T) {
// before // before
runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID, "-a") runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID, "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected = []string{secondID, firstID} expected = []string{secondID, firstID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -102,7 +125,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID) runCmd = exec.Command(dockerBinary, "ps", "--before", thirdID)
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -111,7 +136,9 @@ func TestPsListContainers(t *testing.T) {
// since & before // since & before
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-a") runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected = []string{thirdID, secondID} expected = []string{thirdID, secondID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -120,7 +147,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID) runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID)
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
} }
@ -128,7 +157,9 @@ func TestPsListContainers(t *testing.T) {
// since & limit // since & limit
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2", "-a") runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2", "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected = []string{fourthID, thirdID} expected = []string{fourthID, thirdID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -137,7 +168,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2") runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "-n=2")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -146,7 +179,9 @@ func TestPsListContainers(t *testing.T) {
// before & limit // before & limit
runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1", "-a") runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1", "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected = []string{thirdID} expected = []string{thirdID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -155,7 +190,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1") runCmd = exec.Command(dockerBinary, "ps", "--before", fourthID, "-n=1")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -164,7 +201,9 @@ func TestPsListContainers(t *testing.T) {
// since & before & limit // since & before & limit
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a") runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
expected = []string{thirdID} expected = []string{thirdID}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
@ -173,7 +212,9 @@ func TestPsListContainers(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1") runCmd = exec.Command(dockerBinary, "ps", "--since", firstID, "--before", fourthID, "-n=1")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
if !assertContainerList(out, expected) { if !assertContainerList(out, expected) {
t.Error("Container list is not in the correct order") t.Error("Container list is not in the correct order")
@ -205,7 +246,9 @@ func TestPsListContainersSize(t *testing.T) {
name := "test_size" name := "test_size"
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test") runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
out, _, err := runCommandWithOutput(runCmd) out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
id, err := getIDByName(name) id, err := getIDByName(name)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -222,7 +265,9 @@ func TestPsListContainersSize(t *testing.T) {
case <-time.After(3 * time.Second): case <-time.After(3 * time.Second):
t.Fatalf("Calling \"docker ps -s\" timed out!") t.Fatalf("Calling \"docker ps -s\" timed out!")
} }
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
lines := strings.Split(strings.Trim(out, "\n "), "\n") lines := strings.Split(strings.Trim(out, "\n "), "\n")
sizeIndex := strings.Index(lines[0], "SIZE") sizeIndex := strings.Index(lines[0], "SIZE")
idIndex := strings.Index(lines[0], "CONTAINER ID") idIndex := strings.Index(lines[0], "CONTAINER ID")
@ -247,24 +292,31 @@ func TestPsListContainersFilterStatus(t *testing.T) {
// start exited container // start exited container
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox") runCmd := exec.Command(dockerBinary, "run", "-d", "busybox")
out, _, err := runCommandWithOutput(runCmd) out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
firstID := stripTrailingCharacters(out) firstID := stripTrailingCharacters(out)
// make sure the exited cintainer is not running // make sure the exited cintainer is not running
runCmd = exec.Command(dockerBinary, "wait", firstID) runCmd = exec.Command(dockerBinary, "wait", firstID)
out, _, err = runCommandWithOutput(runCmd) if out, _, err = runCommandWithOutput(runCmd); err != nil {
errorOut(err, t, out) t.Fatal(out, err)
}
// start running container // start running container
runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 360") runCmd = exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 360")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
secondID := stripTrailingCharacters(out) secondID := stripTrailingCharacters(out)
// filter containers by exited // filter containers by exited
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=exited") runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=exited")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
containerOut := strings.TrimSpace(out) containerOut := strings.TrimSpace(out)
if containerOut != firstID[:12] { if containerOut != firstID[:12] {
t.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out) t.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
@ -272,7 +324,9 @@ func TestPsListContainersFilterStatus(t *testing.T) {
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=running") runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--filter=status=running")
out, _, err = runCommandWithOutput(runCmd) out, _, err = runCommandWithOutput(runCmd)
errorOut(err, t, out) if err != nil {
t.Fatal(out, err)
}
containerOut = strings.TrimSpace(out) containerOut = strings.TrimSpace(out)
if containerOut != secondID[:12] { if containerOut != secondID[:12] {
t.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out) t.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)