MCPcopy Create free account
hub / github.com/docker/compose / TestLocalComposeExec

Function TestLocalComposeExec

pkg/e2e/compose_exec_test.go:27–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestLocalComposeExec(t *testing.T) {
28 c := NewParallelCLI(t)
29
30 const projectName = "compose-e2e-exec"
31
32 cmdArgs := func(cmd string, args ...string) []string {
33 ret := []string{"--project-directory", "fixtures/simple-composefile", "--project-name", projectName, cmd}
34 ret = append(ret, args...)
35 return ret
36 }
37
38 cleanup := func() {
39 c.RunDockerComposeCmd(t, cmdArgs("down", "--timeout=0")...)
40 }
41 cleanup()
42 t.Cleanup(cleanup)
43
44 c.RunDockerComposeCmd(t, cmdArgs("up", "-d")...)
45
46 t.Run("exec true", func(t *testing.T) {
47 c.RunDockerComposeCmd(t, cmdArgs("exec", "simple", "/bin/true")...)
48 })
49
50 t.Run("exec false", func(t *testing.T) {
51 res := c.RunDockerComposeCmdNoCheck(t, cmdArgs("exec", "simple", "/bin/false")...)
52 res.Assert(t, icmd.Expected{ExitCode: 1})
53 })
54
55 t.Run("exec with env set", func(t *testing.T) {
56 res := icmd.RunCmd(c.NewDockerComposeCmd(t, cmdArgs("exec", "-e", "FOO", "simple", "/usr/bin/env")...),
57 func(cmd *icmd.Cmd) {
58 cmd.Env = append(cmd.Env, "FOO=BAR")
59 })
60 res.Assert(t, icmd.Expected{Out: "FOO=BAR"})
61 })
62
63 t.Run("exec without env set", func(t *testing.T) {
64 res := c.RunDockerComposeCmd(t, cmdArgs("exec", "-e", "FOO", "simple", "/usr/bin/env")...)
65 assert.Check(t, !strings.Contains(res.Stdout(), "FOO="), res.Combined())
66 })
67}
68
69func TestLocalComposeExecOneOff(t *testing.T) {
70 c := NewParallelCLI(t)

Callers

nothing calls this directly

Calls 5

NewParallelCLIFunction · 0.85
RunDockerComposeCmdMethod · 0.80
RunCmdMethod · 0.80
NewDockerComposeCmdMethod · 0.80

Tested by

no test coverage detected