Add a "Created" state for new containers that haven't been run yet

Closes #13353

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis
2015-05-30 07:48:46 -07:00
parent 04c6f09fbd
commit dc697b1c9f
7 changed files with 75 additions and 5 deletions
+51
View File
@@ -680,3 +680,54 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) {
c.Fatalf("docker ps with --size should show virtual size of container")
}
}
func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
// create a container
createCmd := exec.Command(dockerBinary, "create", "busybox")
out, _, err := runCommandWithOutput(createCmd)
if err != nil {
c.Fatal(out, err)
}
cID := strings.TrimSpace(out)
shortCID := cID[:12]
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
runCmd := exec.Command(dockerBinary, "ps", "-q")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
if strings.Contains(out, shortCID) {
c.Fatalf("Should have not seen '%s' in ps output:\n%s", shortCID, out)
}
// Make sure it DOES show up as 'Created' for 'ps -a'
runCmd = exec.Command(dockerBinary, "ps", "-a")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
hits := 0
for _, line := range strings.Split(out, "\n") {
if !strings.Contains(line, shortCID) {
continue
}
hits++
if !strings.Contains(line, "Created") {
c.Fatalf("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)
}
// filter containers by 'create' - note, no -a needed
runCmd = exec.Command(dockerBinary, "ps", "-q", "-f", "status=created")
if out, _, err = runCommandWithOutput(runCmd); err != nil {
c.Fatal(out, err)
}
containerOut := strings.TrimSpace(out)
if !strings.HasPrefix(cID, containerOut) {
c.Fatalf("Expected id %s, got %s for filter, out: %s", cID, containerOut, out)
}
}