(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestLocalComposeRun(t *testing.T) { |
| 31 | c := NewParallelCLI(t) |
| 32 | defer c.cleanupWithDown(t, "run-test") |
| 33 | |
| 34 | t.Run("compose run", func(t *testing.T) { |
| 35 | res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "run", "back") |
| 36 | lines := Lines(res.Stdout()) |
| 37 | assert.Equal(t, lines[len(lines)-1], "Hello there!!", res.Stdout()) |
| 38 | assert.Assert(t, !strings.Contains(res.Combined(), "orphan")) |
| 39 | res = c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "run", "back", "echo", |
| 40 | "Hello one more time") |
| 41 | lines = Lines(res.Stdout()) |
| 42 | assert.Equal(t, lines[len(lines)-1], "Hello one more time", res.Stdout()) |
| 43 | assert.Assert(t, strings.Contains(res.Combined(), "orphan")) |
| 44 | }) |
| 45 | |
| 46 | t.Run("check run container exited", func(t *testing.T) { |
| 47 | res := c.RunDockerCmd(t, "ps", "--all") |
| 48 | lines := Lines(res.Stdout()) |
| 49 | var runContainerID string |
| 50 | var truncatedSlug string |
| 51 | for _, line := range lines { |
| 52 | fields := strings.Fields(line) |
| 53 | containerID := fields[len(fields)-1] |
| 54 | assert.Assert(t, !strings.HasPrefix(containerID, "run-test-front")) |
| 55 | if strings.HasPrefix(containerID, "run-test-back") { |
| 56 | // only the one-off container for back service |
| 57 | assert.Assert(t, strings.HasPrefix(containerID, "run-test-back-run-"), containerID) |
| 58 | truncatedSlug = strings.Replace(containerID, "run-test-back-run-", "", 1) |
| 59 | runContainerID = containerID |
| 60 | } |
| 61 | if strings.HasPrefix(containerID, "run-test-db-1") { |
| 62 | assert.Assert(t, strings.Contains(line, "Up"), line) |
| 63 | } |
| 64 | } |
| 65 | assert.Assert(t, runContainerID != "") |
| 66 | res = c.RunDockerCmd(t, "inspect", runContainerID) |
| 67 | res.Assert(t, icmd.Expected{Out: ` "Status": "exited"`}) |
| 68 | res.Assert(t, icmd.Expected{Out: `"com.docker.compose.project": "run-test"`}) |
| 69 | res.Assert(t, icmd.Expected{Out: `"com.docker.compose.oneoff": "True",`}) |
| 70 | res.Assert(t, icmd.Expected{Out: `"com.docker.compose.slug": "` + truncatedSlug}) |
| 71 | }) |
| 72 | |
| 73 | t.Run("compose run --rm", func(t *testing.T) { |
| 74 | res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "run", "--rm", "back", "echo", |
| 75 | "Hello again") |
| 76 | lines := Lines(res.Stdout()) |
| 77 | assert.Equal(t, lines[len(lines)-1], "Hello again", res.Stdout()) |
| 78 | |
| 79 | res = c.RunDockerCmd(t, "ps", "--all") |
| 80 | assert.Assert(t, strings.Contains(res.Stdout(), "run-test-back"), res.Stdout()) |
| 81 | }) |
| 82 | |
| 83 | t.Run("down", func(t *testing.T) { |
| 84 | c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "down", "--remove-orphans") |
| 85 | res := c.RunDockerCmd(t, "ps", "--all") |
| 86 | assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout()) |
| 87 | }) |
nothing calls this directly
no test coverage detected