add file header and cleanup profiles e2e tests

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2022-11-30 11:53:05 +01:00 committed by Nicolas De loof
parent 5edd783032
commit 707d55c77f
2 changed files with 54 additions and 33 deletions

View File

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

View File

@ -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 package e2e
import ( import (
"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
"strings" "strings"
"testing" "testing"
"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
)
const (
profiledService = "profiled-service"
regularService = "regular-service"
) )
func TestExplicitProfileUsage(t *testing.T) { func TestExplicitProfileUsage(t *testing.T) {
@ -17,8 +39,8 @@ func TestExplicitProfileUsage(t *testing.T) {
"-p", projectName, "--profile", profileName, "up", "-d") "-p", projectName, "--profile", profileName, "up", "-d")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: "profiled-service"}) res.Assert(t, icmd.Expected{Out: regularService})
res.Assert(t, icmd.Expected{Out: "main"}) res.Assert(t, icmd.Expected{Out: profiledService})
}) })
t.Run("compose stop with profile", func(t *testing.T) { t.Run("compose stop with profile", func(t *testing.T) {
@ -26,8 +48,8 @@ func TestExplicitProfileUsage(t *testing.T) {
"-p", projectName, "--profile", profileName, "stop") "-p", projectName, "--profile", profileName, "stop")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") 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(), regularService))
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
}) })
t.Run("compose start with profile", func(t *testing.T) { t.Run("compose start with profile", func(t *testing.T) {
@ -35,8 +57,8 @@ func TestExplicitProfileUsage(t *testing.T) {
"-p", projectName, "--profile", profileName, "start") "-p", projectName, "--profile", profileName, "start")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
res.Assert(t, icmd.Expected{Out: "profiled-service"}) res.Assert(t, icmd.Expected{Out: regularService})
res.Assert(t, icmd.Expected{Out: "main"}) res.Assert(t, icmd.Expected{Out: profiledService})
}) })
t.Run("compose restart with profile", func(t *testing.T) { t.Run("compose restart with profile", func(t *testing.T) {
@ -44,8 +66,8 @@ func TestExplicitProfileUsage(t *testing.T) {
"-p", projectName, "--profile", profileName, "restart") "-p", projectName, "--profile", profileName, "restart")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
res.Assert(t, icmd.Expected{Out: "profiled-service"}) res.Assert(t, icmd.Expected{Out: regularService})
res.Assert(t, icmd.Expected{Out: "main"}) res.Assert(t, icmd.Expected{Out: profiledService})
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
@ -67,8 +89,8 @@ func TestNoProfileUsage(t *testing.T) {
"-p", projectName, "up", "-d") "-p", projectName, "up", "-d")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
res.Assert(t, icmd.Expected{Out: "main"}) res.Assert(t, icmd.Expected{Out: regularService})
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service")) assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
}) })
t.Run("compose stop without profile", func(t *testing.T) { t.Run("compose stop without profile", func(t *testing.T) {
@ -76,8 +98,8 @@ func TestNoProfileUsage(t *testing.T) {
"-p", projectName, "stop") "-p", projectName, "stop")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") 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(), regularService))
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
}) })
t.Run("compose start without profile", func(t *testing.T) { t.Run("compose start without profile", func(t *testing.T) {
@ -85,8 +107,8 @@ func TestNoProfileUsage(t *testing.T) {
"-p", projectName, "start") "-p", projectName, "start")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
res.Assert(t, icmd.Expected{Out: "main"}) res.Assert(t, icmd.Expected{Out: regularService})
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service")) assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
}) })
t.Run("compose restart without profile", func(t *testing.T) { t.Run("compose restart without profile", func(t *testing.T) {
@ -94,8 +116,8 @@ func TestNoProfileUsage(t *testing.T) {
"-p", projectName, "restart") "-p", projectName, "restart")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
res.Assert(t, icmd.Expected{Out: "main"}) res.Assert(t, icmd.Expected{Out: regularService})
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service")) assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
@ -112,38 +134,37 @@ func TestActiveProfileViaTargetedService(t *testing.T) {
c := NewParallelCLI(t) c := NewParallelCLI(t)
const projectName = "compose-e2e-profiles-via-target-service" const projectName = "compose-e2e-profiles-via-target-service"
const profileName = "test-profile" const profileName = "test-profile"
const targetedService = "profiled-service"
t.Run("compose up with service name", func(t *testing.T) { t.Run("compose up with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml", 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.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), regularService))
res.Assert(t, icmd.Expected{Out: targetedService}) res.Assert(t, icmd.Expected{Out: profiledService})
res = c.RunDockerComposeCmd(t, "-p", projectName, "--profile", profileName, "ps") res = c.RunDockerComposeCmd(t, "-p", projectName, "--profile", profileName, "ps")
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), regularService))
res.Assert(t, icmd.Expected{Out: targetedService}) res.Assert(t, icmd.Expected{Out: profiledService})
}) })
t.Run("compose stop with service name", func(t *testing.T) { t.Run("compose stop with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml", 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.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), regularService))
assert.Assert(t, !strings.Contains(res.Combined(), targetedService)) assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
}) })
t.Run("compose start with service name", func(t *testing.T) { t.Run("compose start with service name", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml", 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.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), regularService))
res.Assert(t, icmd.Expected{Out: targetedService}) res.Assert(t, icmd.Expected{Out: profiledService})
}) })
t.Run("compose restart with service name", func(t *testing.T) { t.Run("compose restart with service name", func(t *testing.T) {
@ -151,8 +172,8 @@ func TestActiveProfileViaTargetedService(t *testing.T) {
"-p", projectName, "restart") "-p", projectName, "restart")
res.Assert(t, icmd.Expected{ExitCode: 0}) res.Assert(t, icmd.Expected{ExitCode: 0})
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running") res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
assert.Assert(t, !strings.Contains(res.Combined(), "main")) assert.Assert(t, !strings.Contains(res.Combined(), regularService))
res.Assert(t, icmd.Expected{Out: targetedService}) res.Assert(t, icmd.Expected{Out: profiledService})
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {