add c.Assert in docker_cli_ps_test.go

Signed-off-by: Zhang Kun <zkazure@gmail.com>
This commit is contained in:
Zhang Kun 2015-10-14 15:03:09 +08:00
parent c9208953fa
commit 83b03b0057
1 changed files with 85 additions and 204 deletions

View File

@ -6,11 +6,11 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"strconv"
"strings"
"time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
"sort"
@ -33,111 +33,79 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
fourthID := strings.TrimSpace(out)
// make sure the second is running
c.Assert(waitRun(secondID), check.IsNil)
c.Assert(waitRun(secondID), checker.IsNil)
// make sure third one is not running
dockerCmd(c, "wait", thirdID)
// make sure the forth is running
c.Assert(waitRun(fourthID), check.IsNil)
c.Assert(waitRun(fourthID), checker.IsNil)
// all
out, _ = dockerCmd(c, "ps", "-a")
if !assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}) {
c.Errorf("ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, []string{fourthID, thirdID, secondID, firstID}), checker.Equals, true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out))
// running
out, _ = dockerCmd(c, "ps")
if !assertContainerList(out, []string{fourthID, secondID, firstID}) {
c.Errorf("RUNNING: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
// from here all flag '-a' is ignored
// limit
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
expected := []string{fourthID, thirdID}
if !assertContainerList(out, expected) {
c.Errorf("LIMIT & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-n=2")
if !assertContainerList(out, expected) {
c.Errorf("LIMIT: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
// since
out, _ = dockerCmd(c, "ps", "--since", firstID, "-a")
expected = []string{fourthID, thirdID, secondID}
if !assertContainerList(out, expected) {
c.Errorf("SINCE & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--since", firstID)
if !assertContainerList(out, expected) {
c.Errorf("SINCE: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE: Container list is not in the correct order: \n%s", out))
// before
out, _ = dockerCmd(c, "ps", "--before", thirdID, "-a")
expected = []string{secondID, firstID}
if !assertContainerList(out, expected) {
c.Errorf("BEFORE & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--before", thirdID)
if !assertContainerList(out, expected) {
c.Errorf("BEFORE: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE: Container list is not in the correct order: \n%s", out))
// since & before
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-a")
expected = []string{thirdID, secondID}
if !assertContainerList(out, expected) {
c.Errorf("SINCE, BEFORE & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID)
if !assertContainerList(out, expected) {
c.Errorf("SINCE, BEFORE: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE: Container list is not in the correct order: \n%s", out))
// since & limit
out, _ = dockerCmd(c, "ps", "--since", firstID, "-n=2", "-a")
expected = []string{fourthID, thirdID}
if !assertContainerList(out, expected) {
c.Errorf("SINCE, LIMIT & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--since", firstID, "-n=2")
if !assertContainerList(out, expected) {
c.Errorf("SINCE, LIMIT: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT: Container list is not in the correct order: \n%s", out))
// before & limit
out, _ = dockerCmd(c, "ps", "--before", fourthID, "-n=1", "-a")
expected = []string{thirdID}
if !assertContainerList(out, expected) {
c.Errorf("BEFORE, LIMIT & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--before", fourthID, "-n=1")
if !assertContainerList(out, expected) {
c.Errorf("BEFORE, LIMIT: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-n=1", "-a")
expected = []string{thirdID}
if !assertContainerList(out, expected) {
c.Errorf("SINCE, BEFORE, LIMIT & ALL: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "--since", firstID, "--before", fourthID, "-n=1")
if !assertContainerList(out, expected) {
c.Errorf("SINCE, BEFORE, LIMIT: Container list is not in the correct order: \n%s", out)
}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT: Container list is not in the correct order: \n%s", out))
}
@ -167,16 +135,12 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
baseSizeIndex := strings.Index(baseLines[0], "SIZE")
baseFoundsize := baseLines[1][baseSizeIndex:]
baseBytes, err := strconv.Atoi(strings.Split(baseFoundsize, " ")[0])
if err != nil {
c.Fatal(err)
}
c.Assert(err, checker.IsNil)
name := "test_size"
out, _ := dockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
id, err := getIDByName(name)
if err != nil {
c.Fatal(err)
}
c.Assert(err, checker.IsNil)
runCmd := exec.Command(dockerBinary, "ps", "-s", "-n=1")
@ -190,24 +154,16 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
case <-time.After(3 * time.Second):
c.Fatalf("Calling \"docker ps -s\" timed out!")
}
if err != nil {
c.Fatal(out, err)
}
c.Assert(err, checker.IsNil)
lines := strings.Split(strings.Trim(out, "\n "), "\n")
if len(lines) != 2 {
c.Fatalf("Expected 2 lines for 'ps -s -n=1' output, got %d", len(lines))
}
c.Assert(lines, checker.HasLen, 2, check.Commentf("Expected 2 lines for 'ps -s -n=1' output, got %d", len(lines)))
sizeIndex := strings.Index(lines[0], "SIZE")
idIndex := strings.Index(lines[0], "CONTAINER ID")
foundID := lines[1][idIndex : idIndex+12]
if foundID != id[:12] {
c.Fatalf("Expected id %s, got %s", id[:12], foundID)
}
c.Assert(foundID, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID))
expectedSize := fmt.Sprintf("%d B", (2 + baseBytes))
foundSize := lines[1][sizeIndex:]
if !strings.Contains(foundSize, expectedSize) {
c.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
}
c.Assert(foundSize, checker.Contains, expectedSize, check.Commentf("Expected size %q, got %q", expectedSize, foundSize))
}
@ -230,20 +186,14 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
// filter containers by exited
out, _ = dockerCmd(c, "ps", "-q", "--filter=status=exited")
containerOut := strings.TrimSpace(out)
if containerOut != firstID[:12] {
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
}
c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=status=running")
containerOut = strings.TrimSpace(out)
if containerOut != secondID[:12] {
c.Fatalf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out)
}
c.Assert(containerOut, checker.Equals, secondID[:12], check.Commentf("Expected id %s, got %s for running filter, output: %q", secondID[:12], containerOut, out))
out, _, _ = dockerCmdWithTimeout(time.Second*60, "ps", "-a", "-q", "--filter=status=rubbish")
if !strings.Contains(out, "Unrecognised filter value for status") {
c.Fatalf("Expected error response due to invalid status filter output: %q", out)
}
c.Assert(out, checker.Contains, "Unrecognised filter value for status", check.Commentf("Expected error response due to invalid status filter output: %q", out))
}
@ -259,9 +209,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
// filter containers by id
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
containerOut := strings.TrimSpace(out)
if containerOut != firstID[:12] {
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
}
c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
}
@ -277,9 +225,7 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
// filter containers by name
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
containerOut := strings.TrimSpace(out)
if containerOut != firstID[:12] {
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out)
}
c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
}
@ -298,19 +244,19 @@ func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
imageID1, err := buildImage(imageName1,
`FROM busybox
LABEL match me 1`, true)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
imageName1Tagged := "images_ps_filter_test1:tag"
imageID1Tagged, err := buildImage(imageName1Tagged,
`FROM busybox
LABEL match me 1 tagged`, true)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
imageName2 := "images_ps_filter_test2"
imageID2, err := buildImage(imageName2,
fmt.Sprintf(`FROM %s
LABEL match me 2`, imageName1), true)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
// start containers
out, _ := dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
@ -373,9 +319,7 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
sort.Strings(actualIDs)
sort.Strings(expectedIDs)
if len(actualIDs) != len(expectedIDs) {
c.Fatalf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs)
}
c.Assert(actualIDs, checker.HasLen, len(expectedIDs), check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
if len(expectedIDs) > 0 {
same := true
for i := range expectedIDs {
@ -385,9 +329,7 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
break
}
}
if !same {
c.Fatalf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs)
}
c.Assert(same, checker.Equals, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
}
}
@ -408,30 +350,24 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
// filter containers by exact match
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
containerOut := strings.TrimSpace(out)
if containerOut != firstID {
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
}
c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
// filter containers by two labels
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
containerOut = strings.TrimSpace(out)
if containerOut != firstID {
c.Fatalf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out)
}
c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
// filter containers by two labels, but expect not found because of AND behavior
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
containerOut = strings.TrimSpace(out)
if containerOut != "" {
c.Fatalf("Expected nothing, got %s for exited filter, output: %q", containerOut, out)
}
c.Assert(containerOut, checker.Equals, "", check.Commentf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
// filter containers by exact key
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
containerOut = strings.TrimSpace(out)
if (!strings.Contains(containerOut, firstID) || !strings.Contains(containerOut, secondID)) || strings.Contains(containerOut, thirdID) {
c.Fatalf("Expected ids %s,%s, got %s for exited filter, output: %q", firstID, secondID, containerOut, out)
}
c.Assert(containerOut, checker.Contains, firstID)
c.Assert(containerOut, checker.Contains, secondID)
c.Assert(containerOut, checker.Not(checker.Contains), thirdID)
}
func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
@ -440,57 +376,35 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
dockerCmd(c, "run", "--name", "zero1", "busybox", "true")
firstZero, err := getIDByName("zero1")
if err != nil {
c.Fatal(err)
}
c.Assert(err, checker.IsNil)
dockerCmd(c, "run", "--name", "zero2", "busybox", "true")
secondZero, err := getIDByName("zero2")
if err != nil {
c.Fatal(err)
}
c.Assert(err, checker.IsNil)
if out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false"); err == nil {
c.Fatal("Should fail.", out, err)
}
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
firstNonZero, err := getIDByName("nonzero1")
if err != nil {
c.Fatal(err)
}
c.Assert(err, checker.IsNil)
if out, _, err := dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false"); err == nil {
c.Fatal("Should fail.", out, err)
}
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
c.Assert(err, checker.NotNil, check.Commentf("Should fail.", out, err))
secondNonZero, err := getIDByName("nonzero2")
if err != nil {
c.Fatal(err)
}
c.Assert(err, checker.IsNil)
// filter containers by exited=0
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
ids := strings.Split(strings.TrimSpace(out), "\n")
if len(ids) != 2 {
c.Fatalf("Should be 2 zero exited containers got %d: %s", len(ids), out)
}
if ids[0] != secondZero {
c.Fatalf("First in list should be %q, got %q", secondZero, ids[0])
}
if ids[1] != firstZero {
c.Fatalf("Second in list should be %q, got %q", firstZero, ids[1])
}
c.Assert(ids, checker.HasLen, 2, check.Commentf("Should be 2 zero exited containers got %d: %s", len(ids), out))
c.Assert(ids[0], checker.Equals, secondZero, check.Commentf("First in list should be %q, got %q", secondZero, ids[0]))
c.Assert(ids[1], checker.Equals, firstZero, check.Commentf("Second in list should be %q, got %q", firstZero, ids[1]))
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
ids = strings.Split(strings.TrimSpace(out), "\n")
if len(ids) != 2 {
c.Fatalf("Should be 2 zero exited containers got %d", len(ids))
}
if ids[0] != secondNonZero {
c.Fatalf("First in list should be %q, got %q", secondNonZero, ids[0])
}
if ids[1] != firstNonZero {
c.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1])
}
c.Assert(ids, checker.HasLen, 2, check.Commentf("Should be 2 zero exited containers got %d", len(ids)))
c.Assert(ids[0], checker.Equals, secondNonZero, check.Commentf("First in list should be %q, got %q", secondNonZero, ids[0]))
c.Assert(ids[1], checker.Equals, firstNonZero, check.Commentf("Second in list should be %q, got %q", firstNonZero, ids[1]))
}
@ -519,24 +433,16 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// skip header
lines = lines[1:]
if len(lines) != 3 {
c.Fatalf("There should be 3 running container, got %d", len(lines))
}
c.Assert(lines, checker.HasLen, 3, check.Commentf("There should be 3 running container, got %d", len(lines)))
for _, line := range lines {
f := strings.Fields(line)
switch f[0] {
case id1:
if f[1] != "busybox" {
c.Fatalf("Expected %s tag for id %s, got %s", "busybox", id1, f[1])
}
c.Assert(f[1], checker.Equals, "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
case id2:
if f[1] != tag {
c.Fatalf("Expected %s tag for id %s, got %s", tag, id2, f[1])
}
c.Assert(f[1], checker.Equals, tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
case id3:
if f[1] != imageID {
c.Fatalf("Expected %s imageID for id %s, got %s", tag, id3, f[1])
}
c.Assert(f[1], checker.Equals, imageID, check.Commentf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
default:
c.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3)
}
@ -558,9 +464,7 @@ func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
fields := strings.Fields(l)
names = append(names, fields[len(fields)-1])
}
if !reflect.DeepEqual(expected, names) {
c.Fatalf("Expected array: %v, got: %v", expected, names)
}
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array: %v, got: %v", expected, names))
}
func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
@ -570,10 +474,7 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
out, _ := dockerCmd(c, "ps")
// check that the port range is in the output
if !strings.Contains(string(out), portRange) {
c.Fatalf("docker ps output should have had the port range %q: %s", portRange, string(out))
}
c.Assert(string(out), checker.Contains, portRange, check.Commentf("docker ps output should have had the port range %q: %s", portRange, string(out)))
}
@ -582,9 +483,7 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) {
dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
out, _ := dockerCmd(c, "ps", "--size")
if !strings.Contains(out, "virtual") {
c.Fatalf("docker ps with --size should show virtual size of container")
}
c.Assert(out, checker.Contains, "virtual", check.Commentf("docker ps with --size should show virtual size of container"))
}
func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
@ -596,9 +495,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
out, _ = dockerCmd(c, "ps", "-q")
if strings.Contains(out, shortCID) {
c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out)
}
c.Assert(out, checker.Not(checker.Contains), shortCID, check.Commentf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
// Make sure it DOES show up as 'Created' for 'ps -a'
out, _ = dockerCmd(c, "ps", "-a")
@ -609,21 +506,15 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
continue
}
hits++
if !strings.Contains(line, "Created") {
c.Fatalf("Missing 'Created' on '%s'", line)
}
c.Assert(line, checker.Contains, "Created", check.Commentf("Missing 'Created' on '%s'", line))
}
if hits != 1 {
c.Fatalf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out)
}
c.Assert(hits, checker.Equals, 1, check.Commentf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
// filter containers by 'create' - note, no -a needed
out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
containerOut := strings.TrimSpace(out)
if !strings.HasPrefix(cID, containerOut) {
c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out)
}
c.Assert(cID, checker.HasPrefix, containerOut)
}
func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
@ -640,9 +531,7 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
for _, l := range lines {
names = append(names, l)
}
if !reflect.DeepEqual(expected, names) {
c.Fatalf("Expected array with non-truncated names: %v, got: %v", expected, names)
}
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with non-truncated names: %v, got: %v", expected, names))
//now list without turning off truncation and make sure we only get the non-link names
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}}")
@ -652,9 +541,7 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
for _, l := range lines {
truncNames = append(truncNames, l)
}
if !reflect.DeepEqual(expected, truncNames) {
c.Fatalf("Expected array with truncated names: %v, got: %v", expected, truncNames)
}
c.Assert(expected, checker.DeepEquals, truncNames, check.Commentf("Expected array with truncated names: %v, got: %v", expected, truncNames))
}
@ -662,16 +549,12 @@ func (s *DockerSuite) TestPsFormatHeaders(c *check.C) {
testRequires(c, DaemonIsLinux)
// make sure no-container "docker ps" still prints the header row
out, _ := dockerCmd(c, "ps", "--format", "table {{.ID}}")
if out != "CONTAINER ID\n" {
c.Fatalf(`Expected 'CONTAINER ID\n', got %v`, out)
}
c.Assert(out, checker.Equals, "CONTAINER ID\n", check.Commentf(`Expected 'CONTAINER ID\n', got %v`, out))
// verify that "docker ps" with a container still prints the header row also
dockerCmd(c, "run", "--name=test", "-d", "busybox", "top")
out, _ = dockerCmd(c, "ps", "--format", "table {{.Names}}")
if out != "NAMES\ntest\n" {
c.Fatalf(`Expected 'NAMES\ntest\n', got %v`, out)
}
c.Assert(out, checker.Equals, "NAMES\ntest\n", check.Commentf(`Expected 'NAMES\ntest\n', got %v`, out))
}
func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
@ -680,19 +563,17 @@ func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
"psFormat": "{{ .ID }} default"
}`
d, err := ioutil.TempDir("", "integration-cli-")
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
defer os.RemoveAll(d)
err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
out, _ := dockerCmd(c, "run", "--name=test", "-d", "busybox", "top")
id := strings.TrimSpace(out)
out, _ = dockerCmd(c, "--config", d, "ps", "-q")
if !strings.HasPrefix(id, strings.TrimSpace(out)) {
c.Fatalf("Expected to print only the container id, got %v\n", out)
}
c.Assert(id, checker.HasPrefix, strings.TrimSpace(out), check.Commentf("Expected to print only the container id, got %v\n", out))
}
// Test for GitHub issue #12595
@ -704,48 +585,48 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
runCmd := exec.Command(dockerBinary, "tag", "busybox:latest", originalImageName)
out, _, err := runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
originalImageID, err := getIDByName(originalImageName)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
runCmd = exec.Command(dockerBinary, "run", "-d", originalImageName, "top")
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
containerID := strings.TrimSpace(out)
linesOut, err := exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
lines := strings.Split(strings.TrimSpace(string(linesOut)), "\n")
// skip header
lines = lines[1:]
c.Assert(len(lines), check.Equals, 1)
c.Assert(len(lines), checker.Equals, 1)
for _, line := range lines {
f := strings.Fields(line)
c.Assert(f[1], check.Equals, originalImageName)
c.Assert(f[1], checker.Equals, originalImageName)
}
runCmd = exec.Command(dockerBinary, "commit", containerID, updatedImageName)
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
runCmd = exec.Command(dockerBinary, "tag", "-f", updatedImageName, originalImageName)
out, _, err = runCommandWithOutput(runCmd)
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
linesOut, err = exec.Command(dockerBinary, "ps", "--no-trunc").CombinedOutput()
c.Assert(err, check.IsNil)
c.Assert(err, checker.IsNil)
lines = strings.Split(strings.TrimSpace(string(linesOut)), "\n")
// skip header
lines = lines[1:]
c.Assert(len(lines), check.Equals, 1)
c.Assert(len(lines), checker.Equals, 1)
for _, line := range lines {
f := strings.Fields(line)
c.Assert(f[1], check.Equals, originalImageID)
c.Assert(f[1], checker.Equals, originalImageID)
}
}