From 49fb4ca25f26cfacc6dd080d1a2a82d134a4529c Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Thu, 16 Jun 2022 08:34:21 -0500 Subject: [PATCH] down: fix COMPOSE_REMOVE_ORPHANS env name and add test Fixes #9562. Signed-off-by: Nick Sieger --- cmd/compose/down.go | 2 +- pkg/e2e/compose_run_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/compose/down.go b/cmd/compose/down.go index a8104fef8b..e94aec1f55 100644 --- a/cmd/compose/down.go +++ b/cmd/compose/down.go @@ -63,7 +63,7 @@ func downCommand(p *projectOptions, backend api.Service) *cobra.Command { ValidArgsFunction: noCompletion(), } flags := downCmd.Flags() - removeOrphans := utils.StringToBool(os.Getenv("COMPOSE_REMOVE_ORPHANS ")) + removeOrphans := utils.StringToBool(os.Getenv("COMPOSE_REMOVE_ORPHANS")) flags.BoolVar(&opts.removeOrphans, "remove-orphans", removeOrphans, "Remove containers for services not defined in the Compose file.") flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds") flags.BoolVarP(&opts.volumes, "volumes", "v", false, " Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.") diff --git a/pkg/e2e/compose_run_test.go b/pkg/e2e/compose_run_test.go index 4fe88dce7c..af46b2dbd3 100644 --- a/pkg/e2e/compose_run_test.go +++ b/pkg/e2e/compose_run_test.go @@ -116,8 +116,10 @@ func TestLocalComposeRun(t *testing.T) { }) t.Run("down", func(t *testing.T) { - c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "down") - c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/orphan.yaml", "down") + cmd := c.NewDockerCmd("compose", "-f", "./fixtures/run-test/compose.yaml", "down") + icmd.RunCmd(cmd, func(c *icmd.Cmd) { + c.Env = append(c.Env, "COMPOSE_REMOVE_ORPHANS=True") + }) res := c.RunDockerCmd(t, "ps", "--all") assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout()) })