From 5edd7830329ddc304320b66a7faeca4653eb7c4e Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Wed, 30 Nov 2022 11:43:58 +0100 Subject: [PATCH] add e2e tests to check profile activation via targeted service Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/e2e/profiles_test.go | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/pkg/e2e/profiles_test.go b/pkg/e2e/profiles_test.go index 799ee24ca..ec1271cbf 100644 --- a/pkg/e2e/profiles_test.go +++ b/pkg/e2e/profiles_test.go @@ -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()) + }) +}