Skip to content

Commit 7fe43a8

Browse files
gloursndeloof
authored andcommitted
add e2e tests using explicitly profiles
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 24ec0b2 commit 7fe43a8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
main:
3+
image: nginx:alpine
4+
5+
profiled-service:
6+
image: nginx:alpine
7+
profiles:
8+
- test-profile

pkg/e2e/profiles_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package e2e
2+
3+
import (
4+
"gotest.tools/v3/assert"
5+
"gotest.tools/v3/icmd"
6+
"strings"
7+
"testing"
8+
)
9+
10+
func TestExplicitProfileUsage(t *testing.T) {
11+
c := NewParallelCLI(t)
12+
const projectName = "compose-e2e-profiles"
13+
const profileName = "test-profile"
14+
15+
t.Run("compose up with profile", func(t *testing.T) {
16+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
17+
"-p", projectName, "--profile", profileName, "up", "-d")
18+
res.Assert(t, icmd.Expected{ExitCode: 0})
19+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
20+
res.Assert(t, icmd.Expected{Out: "profiled-service"})
21+
res.Assert(t, icmd.Expected{Out: "main"})
22+
})
23+
24+
t.Run("compose stop with profile", func(t *testing.T) {
25+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
26+
"-p", projectName, "--profile", profileName, "stop")
27+
res.Assert(t, icmd.Expected{ExitCode: 0})
28+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
29+
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
30+
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
31+
})
32+
33+
t.Run("compose start with profile", func(t *testing.T) {
34+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
35+
"-p", projectName, "--profile", profileName, "start")
36+
res.Assert(t, icmd.Expected{ExitCode: 0})
37+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
38+
res.Assert(t, icmd.Expected{Out: "profiled-service"})
39+
res.Assert(t, icmd.Expected{Out: "main"})
40+
})
41+
42+
t.Run("compose restart with profile", func(t *testing.T) {
43+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
44+
"-p", projectName, "--profile", profileName, "restart")
45+
res.Assert(t, icmd.Expected{ExitCode: 0})
46+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
47+
res.Assert(t, icmd.Expected{Out: "profiled-service"})
48+
res.Assert(t, icmd.Expected{Out: "main"})
49+
})
50+
51+
t.Run("down", func(t *testing.T) {
52+
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
53+
})
54+
55+
t.Run("check containers after down", func(t *testing.T) {
56+
res := c.RunDockerCmd(t, "ps", "--all")
57+
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
58+
})
59+
}

0 commit comments

Comments
 (0)