Quellcode durchsuchen

add file header and cleanup profiles e2e tests

Signed-off-by: Guillaume Lours <[email protected]>
Guillaume Lours vor 2 Jahren
Ursprung
Commit
707d55c77f
2 geänderte Dateien mit 54 neuen und 33 gelöschten Zeilen
  1. 1 1
      pkg/e2e/fixtures/profiles/compose.yaml
  2. 53 32
      pkg/e2e/profiles_test.go

+ 1 - 1
pkg/e2e/fixtures/profiles/compose.yaml

@@ -1,5 +1,5 @@
 services:
-  main:
+  regular-service:
     image: nginx:alpine
 
   profiled-service:

+ 53 - 32
pkg/e2e/profiles_test.go

@@ -1,10 +1,32 @@
+/*
+   Copyright 2020 Docker Compose CLI authors
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
 package e2e
 
 import (
-	"gotest.tools/v3/assert"
-	"gotest.tools/v3/icmd"
 	"strings"
 	"testing"
+
+	"gotest.tools/v3/assert"
+	"gotest.tools/v3/icmd"
+)
+
+const (
+	profiledService = "profiled-service"
+	regularService  = "regular-service"
 )
 
 func TestExplicitProfileUsage(t *testing.T) {
@@ -17,8 +39,8 @@ func TestExplicitProfileUsage(t *testing.T) {
 			"-p", projectName, "--profile", profileName, "up", "-d")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
-		res.Assert(t, icmd.Expected{Out: "profiled-service"})
-		res.Assert(t, icmd.Expected{Out: "main"})
+		res.Assert(t, icmd.Expected{Out: regularService})
+		res.Assert(t, icmd.Expected{Out: profiledService})
 	})
 
 	t.Run("compose stop with profile", func(t *testing.T) {
@@ -26,8 +48,8 @@ func TestExplicitProfileUsage(t *testing.T) {
 			"-p", projectName, "--profile", profileName, "stop")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
-		assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
-		assert.Assert(t, !strings.Contains(res.Combined(), "main"))
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
 	})
 
 	t.Run("compose start with profile", func(t *testing.T) {
@@ -35,8 +57,8 @@ func TestExplicitProfileUsage(t *testing.T) {
 			"-p", projectName, "--profile", profileName, "start")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
-		res.Assert(t, icmd.Expected{Out: "profiled-service"})
-		res.Assert(t, icmd.Expected{Out: "main"})
+		res.Assert(t, icmd.Expected{Out: regularService})
+		res.Assert(t, icmd.Expected{Out: profiledService})
 	})
 
 	t.Run("compose restart with profile", func(t *testing.T) {
@@ -44,8 +66,8 @@ func TestExplicitProfileUsage(t *testing.T) {
 			"-p", projectName, "--profile", profileName, "restart")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
-		res.Assert(t, icmd.Expected{Out: "profiled-service"})
-		res.Assert(t, icmd.Expected{Out: "main"})
+		res.Assert(t, icmd.Expected{Out: regularService})
+		res.Assert(t, icmd.Expected{Out: profiledService})
 	})
 
 	t.Run("down", func(t *testing.T) {
@@ -67,8 +89,8 @@ func TestNoProfileUsage(t *testing.T) {
 			"-p", projectName, "up", "-d")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
-		res.Assert(t, icmd.Expected{Out: "main"})
-		assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
+		res.Assert(t, icmd.Expected{Out: regularService})
+		assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
 	})
 
 	t.Run("compose stop without profile", func(t *testing.T) {
@@ -76,8 +98,8 @@ func TestNoProfileUsage(t *testing.T) {
 			"-p", projectName, "stop")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
-		assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
-		assert.Assert(t, !strings.Contains(res.Combined(), "main"))
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
 	})
 
 	t.Run("compose start without profile", func(t *testing.T) {
@@ -85,8 +107,8 @@ func TestNoProfileUsage(t *testing.T) {
 			"-p", projectName, "start")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
-		res.Assert(t, icmd.Expected{Out: "main"})
-		assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
+		res.Assert(t, icmd.Expected{Out: regularService})
+		assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
 	})
 
 	t.Run("compose restart without profile", func(t *testing.T) {
@@ -94,8 +116,8 @@ func TestNoProfileUsage(t *testing.T) {
 			"-p", projectName, "restart")
 		res.Assert(t, icmd.Expected{ExitCode: 0})
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
-		res.Assert(t, icmd.Expected{Out: "main"})
-		assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
+		res.Assert(t, icmd.Expected{Out: regularService})
+		assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
 	})
 
 	t.Run("down", func(t *testing.T) {
@@ -112,38 +134,37 @@ 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")
+			"-p", projectName, "up", profiledService, "-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})
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		res.Assert(t, icmd.Expected{Out: profiledService})
 
 		res = c.RunDockerComposeCmd(t, "-p", projectName, "--profile", profileName, "ps")
-		assert.Assert(t, !strings.Contains(res.Combined(), "main"))
-		res.Assert(t, icmd.Expected{Out: targetedService})
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		res.Assert(t, icmd.Expected{Out: profiledService})
 	})
 
 	t.Run("compose stop with service name", func(t *testing.T) {
 		res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
-			"-p", projectName, "stop", targetedService)
+			"-p", projectName, "stop", profiledService)
 		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))
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
 	})
 
 	t.Run("compose start with service name", func(t *testing.T) {
 		res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
-			"-p", projectName, "start", targetedService)
+			"-p", projectName, "start", profiledService)
 		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})
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		res.Assert(t, icmd.Expected{Out: profiledService})
 	})
 
 	t.Run("compose restart with service name", func(t *testing.T) {
@@ -151,8 +172,8 @@ func TestActiveProfileViaTargetedService(t *testing.T) {
 			"-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})
+		assert.Assert(t, !strings.Contains(res.Combined(), regularService))
+		res.Assert(t, icmd.Expected{Out: profiledService})
 	})
 
 	t.Run("down", func(t *testing.T) {