add e2e tests to check profile activation via targeted service

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2022-11-30 11:43:58 +01:00 committed by Nicolas De loof
parent 6fbef29619
commit 5edd783032
1 changed files with 57 additions and 0 deletions

View File

@ -107,3 +107,60 @@ func TestNoProfileUsage(t *testing.T) {
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
})
}
func TestActiveProfileViaTargetedService(t *testing.T) {
c := NewParallelCLI(t)
const projectName = "compose-e2e-profiles-via-target-service"
const profileName = "test-profile"
const targetedService = "profiled-service"
t.Run("compose up with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
"-p", projectName, "up", targetedService, "-d")
res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
res.Assert(t, icmd.Expected{Out: targetedService})
res = c.RunDockerComposeCmd(t, "-p", projectName, "--profile", profileName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
res.Assert(t, icmd.Expected{Out: targetedService})
})
t.Run("compose stop with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
"-p", projectName, "stop", targetedService)
res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
assert.Assert(t, !strings.Contains(res.Combined(), targetedService))
})
t.Run("compose start with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
"-p", projectName, "start", targetedService)
res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
res.Assert(t, icmd.Expected{Out: targetedService})
})
t.Run("compose restart with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
"-p", projectName, "restart")
res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
res.Assert(t, icmd.Expected{Out: targetedService})
})
t.Run("down", func(t *testing.T) {
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
})
t.Run("check containers after down", func(t *testing.T) {
res := c.RunDockerCmd(t, "ps", "--all")
assert.Assert(t, !strings.Contains(res.Combined(), projectName), res.Combined())
})
}