1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

docker ps --filter exited=status should not show running containers

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
Jessica Frazelle 2015-01-08 14:51:47 -08:00
parent 273472a5c2
commit 81f84023be
2 changed files with 15 additions and 14 deletions

View file

@ -73,7 +73,6 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
if !container.Running && !all && n <= 0 && since == "" && before == "" { if !container.Running && !all && n <= 0 && since == "" && before == "" {
return nil return nil
} }
if !psFilters.Match("name", container.Name) { if !psFilters.Match("name", container.Name) {
return nil return nil
} }
@ -96,10 +95,10 @@ func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
return errLast return errLast
} }
} }
if len(filt_exited) > 0 && !container.Running { if len(filt_exited) > 0 {
should_skip := true should_skip := true
for _, code := range filt_exited { for _, code := range filt_exited {
if code == container.ExitCode { if code == container.ExitCode && !container.Running {
should_skip = false should_skip = false
break break
} }

View file

@ -398,11 +398,15 @@ func TestPsListContainersFilterName(t *testing.T) {
} }
func TestPsListContainersFilterExited(t *testing.T) { func TestPsListContainersFilterExited(t *testing.T) {
deleteAllContainers()
defer deleteAllContainers() defer deleteAllContainers()
runCmd := exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd) runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
if err != nil { if out, _, err := runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
runCmd = exec.Command(dockerBinary, "run", "--name", "zero1", "busybox", "true")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err) t.Fatal(out, err)
} }
firstZero, err := getIDByName("zero1") firstZero, err := getIDByName("zero1")
@ -411,8 +415,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
} }
runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true") runCmd = exec.Command(dockerBinary, "run", "--name", "zero2", "busybox", "true")
out, _, err = runCommandWithOutput(runCmd) if out, _, err := runCommandWithOutput(runCmd); err != nil {
if err != nil {
t.Fatal(out, err) t.Fatal(out, err)
} }
secondZero, err := getIDByName("zero2") secondZero, err := getIDByName("zero2")
@ -421,8 +424,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
} }
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false") runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero1", "busybox", "false")
out, _, err = runCommandWithOutput(runCmd) if out, _, err := runCommandWithOutput(runCmd); err == nil {
if err == nil {
t.Fatal("Should fail.", out, err) t.Fatal("Should fail.", out, err)
} }
firstNonZero, err := getIDByName("nonzero1") firstNonZero, err := getIDByName("nonzero1")
@ -431,8 +433,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
} }
runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false") runCmd = exec.Command(dockerBinary, "run", "--name", "nonzero2", "busybox", "false")
out, _, err = runCommandWithOutput(runCmd) if out, _, err := runCommandWithOutput(runCmd); err == nil {
if err == nil {
t.Fatal("Should fail.", out, err) t.Fatal("Should fail.", out, err)
} }
secondNonZero, err := getIDByName("nonzero2") secondNonZero, err := getIDByName("nonzero2")
@ -442,7 +443,7 @@ func TestPsListContainersFilterExited(t *testing.T) {
// filter containers by exited=0 // filter containers by exited=0
runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0") runCmd = exec.Command(dockerBinary, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
out, _, err = runCommandWithOutput(runCmd) out, _, err := runCommandWithOutput(runCmd)
if err != nil { if err != nil {
t.Fatal(out, err) t.Fatal(out, err)
} }
@ -472,5 +473,6 @@ func TestPsListContainersFilterExited(t *testing.T) {
if ids[1] != firstNonZero { if ids[1] != firstNonZero {
t.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1]) t.Fatalf("Second in list should be %q, got %q", firstNonZero, ids[1])
} }
logDone("ps - test ps filter exited") logDone("ps - test ps filter exited")
} }