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

Function TestLocalComposeRun

pkg/e2e/compose_run_test.go:30–289  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func 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 })

Callers

nothing calls this directly

Calls 8

NewParallelCLIFunction · 0.85
LinesFunction · 0.85
cleanupWithDownMethod · 0.80
RunDockerComposeCmdMethod · 0.80
RunDockerCmdMethod · 0.80
NewDockerComposeCmdMethod · 0.80
RunCmdMethod · 0.80
NewCmdMethod · 0.80

Tested by

no test coverage detected