mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Fix tests that depend on clean environment
Signed-off-by: Christopher Crone <christopher.crone@docker.com>
This commit is contained in:
@ -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,7 +226,7 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,6 +309,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 +373,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 +475,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 +499,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)))
|
||||
@ -581,12 +591,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 +607,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,12 +617,14 @@ 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...)
|
||||
@ -628,6 +643,7 @@ func (s *DockerSuite) TestPsFormatHeaders(c *check.C) {
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
|
||||
existingContainers := ExistingContainerIDs(c)
|
||||
config := `{
|
||||
"psFormat": "default {{ .ID }}"
|
||||
}`
|
||||
@ -642,6 +658,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 +669,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 +683,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 +700,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 +731,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 +759,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 +779,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 +793,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 +805,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 +817,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 +848,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 +867,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 +879,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 +894,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 +915,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,8 +958,10 @@ 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")
|
||||
}
|
||||
|
||||
@ -969,11 +1002,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 +1018,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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user