Browse Source

add e2e tests to check profile activation via targeted service

Signed-off-by: Guillaume Lours <[email protected]>
Guillaume Lours 2 years ago
parent
commit
5edd783032
1 changed files with 57 additions and 0 deletions
  1. 57 0
      pkg/e2e/profiles_test.go

+ 57 - 0
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())
+	})
+}