Skip to content

Commit

Permalink
only list running containers when --all=false
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Dec 16, 2022
1 parent 0eaa249 commit 62b8031
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api
if options.All {
oneOff = oneOffInclude
}
containers, err := s.getContainers(ctx, projectName, oneOff, true, options.Services...)
containers, err := s.getContainers(ctx, projectName, oneOff, options.All, options.Services...)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestPs(t *testing.T) {
ctx := context.Background()
args := filters.NewArgs(projectFilter(strings.ToLower(testProject)))
args.Add("label", "com.docker.compose.oneoff=False")
listOpts := moby.ContainerListOptions{Filters: args, All: true}
listOpts := moby.ContainerListOptions{Filters: args, All: false}
c1, inspect1 := containerDetails("service1", "123", "running", "healthy", 0)
c2, inspect2 := containerDetails("service1", "456", "running", "", 0)
c2.Ports = []moby.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}}
Expand Down
14 changes: 14 additions & 0 deletions pkg/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,18 @@ func TestPs(t *testing.T) {
}
assert.Equal(t, 2, count, "Did not match both services:\n"+res.Combined())
})

t.Run("ps --all", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
assert.NoError(t, res.Error)

res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps")
lines := strings.Split(res.Stdout(), "\n")
assert.Equal(t, 2, len(lines))

res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--all")
lines = strings.Split(res.Stdout(), "\n")
assert.Equal(t, 4, len(lines))
})

}

0 comments on commit 62b8031

Please sign in to comment.