فهرست منبع

only list running containers when --all=false

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 2 سال پیش
والد
کامیت
e42673daed
3فایلهای تغییر یافته به همراه16 افزوده شده و 2 حذف شده
  1. 1 1
      pkg/compose/ps.go
  2. 1 1
      pkg/compose/ps_test.go
  3. 14 0
      pkg/e2e/ps_test.go

+ 1 - 1
pkg/compose/ps.go

@@ -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
 	}

+ 1 - 1
pkg/compose/ps_test.go

@@ -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"}}

+ 14 - 0
pkg/e2e/ps_test.go

@@ -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))
+	})
+
 }