MCPcopy
hub / github.com/docker/compose / TestLocalComposeExecOneOff

Function TestLocalComposeExecOneOff

pkg/e2e/compose_exec_test.go:69–94  ·  pkg/e2e/compose_exec_test.go::TestLocalComposeExecOneOff
(t *testing.T)

Source from the content-addressed store, hash-verified

67}
68
69func TestLocalComposeExecOneOff(t *testing.T) {
70 c := NewParallelCLI(t)
71
72 const projectName = "compose-e2e-exec-one-off"
73 defer c.cleanupWithDown(t, projectName)
74 cmdArgs := func(cmd string, args ...string) []string {
75 ret := []string{"--project-directory", "fixtures/simple-composefile", "--project-name", projectName, cmd}
76 ret = append(ret, args...)
77 return ret
78 }
79
80 c.RunDockerComposeCmd(t, cmdArgs("run", "-d", "simple")...)
81
82 t.Run("exec in one-off container", func(t *testing.T) {
83 res := c.RunDockerComposeCmd(t, cmdArgs("exec", "-e", "FOO", "simple", "/usr/bin/env")...)
84 assert.Check(t, !strings.Contains(res.Stdout(), "FOO="), res.Combined())
85 })
86
87 t.Run("exec with index", func(t *testing.T) {
88 res := c.RunDockerComposeCmdNoCheck(t, cmdArgs("exec", "--index", "1", "-e", "FOO", "simple", "/usr/bin/env")...)
89 res.Assert(t, icmd.Expected{ExitCode: 1, Err: "service \"simple\" is not running container #1"})
90 })
91 cmdResult := c.RunDockerCmd(t, "ps", "-q", "--filter", "label=com.docker.compose.project=compose-e2e-exec-one-off").Stdout()
92 containerIDs := strings.Split(cmdResult, "\n")
93 _ = c.RunDockerOrExitError(t, append([]string{"stop"}, containerIDs...)...)
94}

Callers

nothing calls this directly

Calls 6

NewParallelCLIFunction · 0.85
cleanupWithDownMethod · 0.80
RunDockerComposeCmdMethod · 0.80
RunDockerCmdMethod · 0.80
RunDockerOrExitErrorMethod · 0.80

Tested by

no test coverage detected