Skip to content

Commit 5edd783

Browse files
gloursndeloof
authored andcommitted
add e2e tests to check profile activation via targeted service
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 6fbef29 commit 5edd783

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

pkg/e2e/profiles_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,60 @@ func TestNoProfileUsage(t *testing.T) {
107107
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
108108
})
109109
}
110+
111+
func TestActiveProfileViaTargetedService(t *testing.T) {
112+
c := NewParallelCLI(t)
113+
const projectName = "compose-e2e-profiles-via-target-service"
114+
const profileName = "test-profile"
115+
const targetedService = "profiled-service"
116+
117+
t.Run("compose up with service name", func(t *testing.T) {
118+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
119+
"-p", projectName, "up", targetedService, "-d")
120+
res.Assert(t, icmd.Expected{ExitCode: 0})
121+
122+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
123+
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
124+
res.Assert(t, icmd.Expected{Out: targetedService})
125+
126+
res = c.RunDockerComposeCmd(t, "-p", projectName, "--profile", profileName, "ps")
127+
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
128+
res.Assert(t, icmd.Expected{Out: targetedService})
129+
})
130+
131+
t.Run("compose stop with service name", func(t *testing.T) {
132+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
133+
"-p", projectName, "stop", targetedService)
134+
res.Assert(t, icmd.Expected{ExitCode: 0})
135+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
136+
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
137+
assert.Assert(t, !strings.Contains(res.Combined(), targetedService))
138+
})
139+
140+
t.Run("compose start with service name", func(t *testing.T) {
141+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
142+
"-p", projectName, "start", targetedService)
143+
res.Assert(t, icmd.Expected{ExitCode: 0})
144+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
145+
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
146+
res.Assert(t, icmd.Expected{Out: targetedService})
147+
})
148+
149+
t.Run("compose restart with service name", func(t *testing.T) {
150+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
151+
"-p", projectName, "restart")
152+
res.Assert(t, icmd.Expected{ExitCode: 0})
153+
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
154+
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
155+
res.Assert(t, icmd.Expected{Out: targetedService})
156+
})
157+
158+
t.Run("down", func(t *testing.T) {
159+
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
160+
})
161+
162+
t.Run("check containers after down", func(t *testing.T) {
163+
res := c.RunDockerCmd(t, "ps", "--all")
164+
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
165+
})
166+
}

0 commit comments

Comments
 (0)