Skip to content

Commit e42673d

Browse files
committed
only list running containers when --all=false
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent c37182b commit e42673d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pkg/compose/ps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api
3232
if options.All {
3333
oneOff = oneOffInclude
3434
}
35-
containers, err := s.getContainers(ctx, projectName, oneOff, true, options.Services...)
35+
containers, err := s.getContainers(ctx, projectName, oneOff, options.All, options.Services...)
3636
if err != nil {
3737
return nil, err
3838
}

pkg/compose/ps_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestPs(t *testing.T) {
4646
ctx := context.Background()
4747
args := filters.NewArgs(projectFilter(strings.ToLower(testProject)))
4848
args.Add("label", "com.docker.compose.oneoff=False")
49-
listOpts := moby.ContainerListOptions{Filters: args, All: true}
49+
listOpts := moby.ContainerListOptions{Filters: args, All: false}
5050
c1, inspect1 := containerDetails("service1", "123", "running", "healthy", 0)
5151
c2, inspect2 := containerDetails("service1", "456", "running", "", 0)
5252
c2.Ports = []moby.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}}

pkg/e2e/ps_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,18 @@ func TestPs(t *testing.T) {
9494
}
9595
assert.Equal(t, 2, count, "Did not match both services:\n"+res.Combined())
9696
})
97+
98+
t.Run("ps --all", func(t *testing.T) {
99+
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
100+
assert.NoError(t, res.Error)
101+
102+
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps")
103+
lines := strings.Split(res.Stdout(), "\n")
104+
assert.Equal(t, 2, len(lines))
105+
106+
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--all")
107+
lines = strings.Split(res.Stdout(), "\n")
108+
assert.Equal(t, 4, len(lines))
109+
})
110+
97111
}

0 commit comments

Comments
 (0)