|
@@ -19,6 +19,8 @@ import (
|
|
|
)
|
|
|
|
|
|
func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
+
|
|
|
out := runSleepingContainer(c, "-d")
|
|
|
firstID := strings.TrimSpace(out)
|
|
|
|
|
@@ -43,79 +45,79 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
|
|
|
|
|
|
// all
|
|
|
out, _ = dockerCmd(c, "ps", "-a")
|
|
|
- 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))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []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")
|
|
|
- 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))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// limit
|
|
|
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
|
|
|
expected := []string{fourthID, thirdID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), 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")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-a")
|
|
|
expected = []string{fourthID, thirdID, secondID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID)
|
|
|
expected = []string{fourthID, secondID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+thirdID)
|
|
|
expected = []string{fourthID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter before
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-a")
|
|
|
expected = []string{thirdID, secondID, firstID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID)
|
|
|
expected = []string{secondID, firstID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID)
|
|
|
expected = []string{secondID, firstID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since & before
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-a")
|
|
|
expected = []string{thirdID, secondID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID)
|
|
|
expected = []string{secondID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since & limit
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2", "-a")
|
|
|
expected = []string{fourthID, thirdID}
|
|
|
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter before & limit
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1", "-a")
|
|
|
expected = []string{thirdID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
// filter since & filter before & limit
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1", "-a")
|
|
|
expected = []string{thirdID}
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1")
|
|
|
- c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
+ c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
|
|
|
|
|
|
}
|
|
|
|
|
@@ -185,6 +187,8 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
+
|
|
|
// start exited container
|
|
|
out := cli.DockerCmd(c, "run", "-d", "busybox").Combined()
|
|
|
firstID := strings.TrimSpace(out)
|
|
@@ -199,11 +203,11 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
|
|
// filter containers by exited
|
|
|
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited").Combined()
|
|
|
containerOut := strings.TrimSpace(out)
|
|
|
- c.Assert(containerOut, checker.Equals, firstID)
|
|
|
+ c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, firstID)
|
|
|
|
|
|
out = cli.DockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running").Combined()
|
|
|
containerOut = strings.TrimSpace(out)
|
|
|
- c.Assert(containerOut, checker.Equals, secondID)
|
|
|
+ c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, secondID)
|
|
|
|
|
|
result := cli.Docker(cli.Args("ps", "-a", "-q", "--filter=status=rubbish"), cli.WithTimeout(time.Second*60))
|
|
|
result.Assert(c, icmd.Expected{
|
|
@@ -222,11 +226,12 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
|
|
|
|
|
|
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused").Combined()
|
|
|
containerOut = strings.TrimSpace(out)
|
|
|
- c.Assert(containerOut, checker.Equals, pausedID)
|
|
|
+ c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, pausedID)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
// Test legacy no health check
|
|
|
out := runSleepingContainer(c, "--name=none_legacy")
|
|
|
containerID := strings.TrimSpace(out)
|
|
@@ -264,7 +269,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
|
|
|
waitForHealthStatus(c, "passing_container", "starting", "healthy")
|
|
|
|
|
|
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined()
|
|
|
- containerOut = strings.TrimSpace(out)
|
|
|
+ containerOut = strings.TrimSpace(RemoveOutputForExistingElements(out, existingContainers))
|
|
|
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
|
|
|
}
|
|
|
|
|
@@ -305,6 +310,8 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
|
|
|
// - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2)
|
|
|
// - Filter them out :P
|
|
|
func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
+
|
|
|
// Build images
|
|
|
imageName1 := "images_ps_filter_test1"
|
|
|
buildImageSuccessfully(c, imageName1, build.WithDockerfile(`FROM busybox
|
|
@@ -367,12 +374,12 @@ func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
|
|
|
var out string
|
|
|
for _, filter := range filterTestSuite {
|
|
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+filter.filterName)
|
|
|
- checkPsAncestorFilterOutput(c, out, filter.filterName, filter.expectedIDs)
|
|
|
+ checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), filter.filterName, filter.expectedIDs)
|
|
|
}
|
|
|
|
|
|
// Multiple ancestor filter
|
|
|
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageName2, "--filter=ancestor="+imageName1Tagged)
|
|
|
- checkPsAncestorFilterOutput(c, out, imageName2+","+imageName1Tagged, []string{fourthID, fifthID})
|
|
|
+ checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), imageName2+","+imageName1Tagged, []string{fourthID, fifthID})
|
|
|
}
|
|
|
|
|
|
func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expectedIDs []string) {
|
|
@@ -469,6 +476,9 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
|
|
|
func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
|
|
// TODO Investigate further why this fails on Windows to Windows CI
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
+
|
|
|
+ existingContainers := ExistingContainerNames(c)
|
|
|
+
|
|
|
tag := "asybox:shmatest"
|
|
|
dockerCmd(c, "tag", "busybox", tag)
|
|
|
|
|
@@ -490,6 +500,7 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "--no-trunc")
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
// skip header
|
|
|
lines = lines[1:]
|
|
|
c.Assert(lines, checker.HasLen, 3, check.Commentf("There should be 3 running container, got %d", len(lines)))
|
|
@@ -511,6 +522,7 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
|
|
|
func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
|
|
|
// Problematic on Windows as it doesn't support links as of Jan 2016
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
runSleepingContainer(c, "--name=first")
|
|
|
runSleepingContainer(c, "--name=second", "--link=first:first")
|
|
|
|
|
@@ -518,6 +530,7 @@ func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
// strip header
|
|
|
lines = lines[1:]
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
expected := []string{"second", "first,second/first"}
|
|
|
var names []string
|
|
|
for _, l := range lines {
|
|
@@ -581,12 +594,14 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
|
|
|
func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
|
|
|
// Problematic on Windows as it doesn't support link as of Jan 2016
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
+ existingContainers := ExistingContainerNames(c)
|
|
|
//create 2 containers and link them
|
|
|
dockerCmd(c, "run", "--name=child", "-d", "busybox", "top")
|
|
|
dockerCmd(c, "run", "--name=parent", "--link=child:linkedone", "-d", "busybox", "top")
|
|
|
|
|
|
//use the new format capabilities to only list the names and --no-trunc to get all names
|
|
|
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}}", "--no-trunc")
|
|
|
+ out = RemoveOutputForExistingElements(out, existingContainers)
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
expected := []string{"parent", "child,parent/linkedone"}
|
|
|
var names []string
|
|
@@ -595,6 +610,7 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
|
|
|
|
|
|
//now list without turning off truncation and make sure we only get the non-link names
|
|
|
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}}")
|
|
|
+ out = RemoveOutputForExistingElements(out, existingContainers)
|
|
|
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
expected = []string{"parent", "child"}
|
|
|
var truncNames []string
|
|
@@ -604,30 +620,22 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
|
|
|
|
|
|
// Test for GitHub issue #21772
|
|
|
func (s *DockerSuite) TestPsNamesMultipleTime(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerNames(c)
|
|
|
runSleepingContainer(c, "--name=test1")
|
|
|
runSleepingContainer(c, "--name=test2")
|
|
|
|
|
|
//use the new format capabilities to list the names twice
|
|
|
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Names}}")
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
expected := []string{"test2 test2", "test1 test1"}
|
|
|
var names []string
|
|
|
names = append(names, lines...)
|
|
|
c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names))
|
|
|
}
|
|
|
|
|
|
-func (s *DockerSuite) TestPsFormatHeaders(c *check.C) {
|
|
|
- // make sure no-container "docker ps" still prints the header row
|
|
|
- out, _ := dockerCmd(c, "ps", "--format", "table {{.ID}}")
|
|
|
- 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
|
|
|
- runSleepingContainer(c, "--name=test")
|
|
|
- out, _ = dockerCmd(c, "ps", "--format", "table {{.Names}}")
|
|
|
- c.Assert(out, checker.Equals, "NAMES\ntest\n", check.Commentf(`Expected 'NAMES\ntest\n', got %v`, out))
|
|
|
-}
|
|
|
-
|
|
|
func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
config := `{
|
|
|
"psFormat": "default {{ .ID }}"
|
|
|
}`
|
|
@@ -642,6 +650,7 @@ func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
out, _ = dockerCmd(c, "--config", d, "ps", "-q")
|
|
|
+ out = RemoveOutputForExistingElements(out, existingContainers)
|
|
|
c.Assert(id, checker.HasPrefix, strings.TrimSpace(out), check.Commentf("Expected to print only the container id, got %v\n", out))
|
|
|
}
|
|
|
|
|
@@ -652,6 +661,8 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
|
|
originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
|
|
|
updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated"
|
|
|
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
+
|
|
|
icmd.RunCommand(dockerBinary, "tag", "busybox:latest", originalImageName).Assert(c, icmd.Success)
|
|
|
|
|
|
originalImageID := getIDByName(c, originalImageName)
|
|
@@ -664,6 +675,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
|
|
result.Assert(c, icmd.Success)
|
|
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(result.Combined())), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
// skip header
|
|
|
lines = lines[1:]
|
|
|
c.Assert(len(lines), checker.Equals, 1)
|
|
@@ -680,6 +692,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
|
|
|
result.Assert(c, icmd.Success)
|
|
|
|
|
|
lines = strings.Split(strings.TrimSpace(string(result.Combined())), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
// skip header
|
|
|
lines = lines[1:]
|
|
|
c.Assert(len(lines), checker.Equals, 1)
|
|
@@ -710,6 +723,8 @@ func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerNames(c)
|
|
|
+
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
|
|
|
|
|
mp := prefix + slash + "test"
|
|
@@ -736,6 +751,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|
|
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}")
|
|
|
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
c.Assert(lines, checker.HasLen, 3)
|
|
|
|
|
|
fields := strings.Fields(lines[0])
|
|
@@ -755,6 +771,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|
|
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=ps-volume-test")
|
|
|
|
|
|
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
c.Assert(lines, checker.HasLen, 1)
|
|
|
|
|
|
fields = strings.Fields(lines[0])
|
|
@@ -768,6 +785,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|
|
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+mp)
|
|
|
|
|
|
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
c.Assert(lines, checker.HasLen, 2)
|
|
|
|
|
|
fields = strings.Fields(lines[0])
|
|
@@ -779,6 +797,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|
|
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource)
|
|
|
|
|
|
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
c.Assert(lines, checker.HasLen, 1)
|
|
|
|
|
|
fields = strings.Fields(lines[0])
|
|
@@ -790,6 +809,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
|
|
|
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination)
|
|
|
|
|
|
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
c.Assert(lines, checker.HasLen, 1)
|
|
|
|
|
|
fields = strings.Fields(lines[0])
|
|
@@ -820,6 +840,8 @@ func (s *DockerSuite) TestPsFormatSize(c *check.C) {
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|
|
+ existing := ExistingContainerIDs(c)
|
|
|
+
|
|
|
// TODO default network on Windows is not called "bridge", and creating a
|
|
|
// custom network fails on Windows fails with "Error response from daemon: plugin not found")
|
|
|
testRequires(c, DaemonIsLinux)
|
|
@@ -837,7 +859,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|
|
lines = lines[1:]
|
|
|
|
|
|
// ps output should have no containers
|
|
|
- c.Assert(lines, checker.HasLen, 0)
|
|
|
+ c.Assert(RemoveLinesForExistingElements(lines, existing), checker.HasLen, 0)
|
|
|
|
|
|
// Filter docker ps on network bridge
|
|
|
out, _ = dockerCmd(c, "ps", "--filter", "network=bridge")
|
|
@@ -849,7 +871,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|
|
lines = lines[1:]
|
|
|
|
|
|
// ps output should have only one container
|
|
|
- c.Assert(lines, checker.HasLen, 1)
|
|
|
+ c.Assert(RemoveLinesForExistingElements(lines, existing), checker.HasLen, 1)
|
|
|
|
|
|
// Making sure onbridgenetwork is on the output
|
|
|
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
|
|
@@ -864,7 +886,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|
|
lines = lines[1:]
|
|
|
|
|
|
//ps output should have both the containers
|
|
|
- c.Assert(lines, checker.HasLen, 2)
|
|
|
+ c.Assert(RemoveLinesForExistingElements(lines, existing), checker.HasLen, 2)
|
|
|
|
|
|
// Making sure onbridgenetwork and onnonenetwork is on the output
|
|
|
c.Assert(containerOut, checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n"))
|
|
@@ -885,11 +907,12 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
|
|
|
containerOut = strings.TrimSpace(string(out))
|
|
|
|
|
|
lines = strings.Split(containerOut, "\n")
|
|
|
+
|
|
|
// skip header
|
|
|
lines = lines[1:]
|
|
|
|
|
|
// ps output should have only one container
|
|
|
- c.Assert(lines, checker.HasLen, 1)
|
|
|
+ c.Assert(RemoveLinesForExistingElements(lines, existing), checker.HasLen, 1)
|
|
|
|
|
|
// Making sure onbridgenetwork is on the output
|
|
|
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
|
|
@@ -927,13 +950,16 @@ func (s *DockerSuite) TestPsFilterMissingArgErrorCode(c *check.C) {
|
|
|
|
|
|
// Test case for 30291
|
|
|
func (s *DockerSuite) TestPsFormatTemplateWithArg(c *check.C) {
|
|
|
+ existingContainers := ExistingContainerNames(c)
|
|
|
runSleepingContainer(c, "-d", "--name", "top", "--label", "some.label=label.foo-bar")
|
|
|
out, _ := dockerCmd(c, "ps", "--format", `{{.Names}} {{.Label "some.label"}}`)
|
|
|
+ out = RemoveOutputForExistingElements(out, existingContainers)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, "top label.foo-bar")
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
+ existingContainers := ExistingContainerIDs(c)
|
|
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "--publish=80", "busybox", "top")
|
|
|
id1 := strings.TrimSpace(out)
|
|
@@ -962,6 +988,7 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
|
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8080/tcp")
|
|
|
+ out = RemoveOutputForExistingElements(out, existingContainers)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, id2)
|
|
|
}
|
|
@@ -969,11 +996,14 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
|
|
|
func (s *DockerSuite) TestPsNotShowLinknamesOfDeletedContainer(c *check.C) {
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
+ existingContainers := ExistingContainerNames(c)
|
|
|
+
|
|
|
dockerCmd(c, "create", "--name=aaa", "busybox", "top")
|
|
|
dockerCmd(c, "create", "--name=bbb", "--link=aaa", "busybox", "top")
|
|
|
|
|
|
out, _ := dockerCmd(c, "ps", "--no-trunc", "-a", "--format", "{{.Names}}")
|
|
|
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
+ lines = RemoveLinesForExistingElements(lines, existingContainers)
|
|
|
expected := []string{"bbb", "aaa,bbb/aaa"}
|
|
|
var names []string
|
|
|
names = append(names, lines...)
|
|
@@ -982,5 +1012,6 @@ func (s *DockerSuite) TestPsNotShowLinknamesOfDeletedContainer(c *check.C) {
|
|
|
dockerCmd(c, "rm", "bbb")
|
|
|
|
|
|
out, _ = dockerCmd(c, "ps", "--no-trunc", "-a", "--format", "{{.Names}}")
|
|
|
+ out = RemoveOutputForExistingElements(out, existingContainers)
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, "aaa")
|
|
|
}
|