Adding network filter to docker ps command

Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
Upstream-commit: 912af1ae8f22c4d9d7e478d0985a40b41ded2027
Component: engine
This commit is contained in:
Sainath Grandhi
2016-05-27 12:20:31 -07:00
committed by Sebastiaan van Stijn
parent 4d60d70438
commit 4e024e3e7d
6 changed files with 66 additions and 1 deletions

View File

@ -804,3 +804,40 @@ func (s *DockerSuite) TestPsFormatSize(c *check.C) {
lines = strings.Split(out, "\n")
c.Assert(lines[8], checker.HasPrefix, "size:", check.Commentf("Size should be appended on a newline"))
}
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
// create a container
out, _ := runSleepingContainer(c, "--net=bridge", "--name=onbridgenetwork")
out, _ = runSleepingContainer(c, "--net=none", "--name=onnonenetwork")
// Filter docker ps on network bridge
out, _ = dockerCmd(c, "ps", "--filter", "network=bridge")
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)
// Making sure onbridgenetwork is on the output
c.Assert(lines[0], checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
// Filter docker ps on networks bridge and none
out, _ = dockerCmd(c, "ps", "--filter", "network=bridge", "--filter", "network=none")
containerOut = strings.TrimSpace(string(out))
lines = strings.Split(containerOut, "\n")
// skip header
lines = lines[1:]
//ps output should have both the containers
c.Assert(lines, checker.HasLen, 2)
// Making sure onbridgenetwork and onnonenetwork is on the output
c.Assert(lines[0], checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n"))
c.Assert(lines[1], checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on bridge network\n"))
}