瀏覽代碼

Fix issue `docker compose rm -s` not removing containers

Signed-off-by: Hironao OTSUBO <[email protected]>
Hironao OTSUBO 4 年之前
父節點
當前提交
1a0efdd413
共有 2 個文件被更改,包括 28 次插入1 次删除
  1. 4 1
      cmd/compose/remove.go
  2. 24 0
      pkg/e2e/compose_test.go

+ 4 - 1
cmd/compose/remove.go

@@ -65,9 +65,12 @@ func runRemove(ctx context.Context, backend api.Service, opts removeOptions, ser
 	}
 
 	if opts.stop {
-		return backend.Stop(ctx, project, api.StopOptions{
+		err := backend.Stop(ctx, project, api.StopOptions{
 			Services: services,
 		})
+		if err != nil {
+			return err
+		}
 	}
 
 	return backend.Remove(ctx, project, api.RemoveOptions{

+ 24 - 0
pkg/e2e/compose_test.go

@@ -171,3 +171,27 @@ func TestInitContainer(t *testing.T) {
 	defer c.RunDockerOrExitError("compose", "-p", "init-container", "down")
 	testify.Regexp(t, "foo_1  | hello(?m:.*)bar_1  | world", res.Stdout())
 }
+
+func TestRm(t *testing.T) {
+	c := NewParallelE2eCLI(t, binDir)
+
+	const projectName = "compose-e2e-rm"
+
+	t.Run("up", func(t *testing.T) {
+		c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
+	})
+
+	t.Run("rm -sf", func(t *testing.T) {
+		res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple")
+		res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
+	})
+
+	t.Run("check containers after rm -sf", func(t *testing.T) {
+		res := c.RunDockerCmd("ps", "--all")
+		assert.Assert(t, !strings.Contains(res.Combined(), projectName+"_simple"), res.Combined())
+	})
+
+	t.Run("down", func(t *testing.T) {
+		c.RunDockerCmd("compose", "-p", projectName, "down")
+	})
+}