(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func 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 | |
| 69 | func TestLocalComposeExecOneOff(t *testing.T) { |
| 70 | c := NewParallelCLI(t) |
nothing calls this directly
no test coverage detected