Skip to content

Commit 707d55c

Browse files
gloursndeloof
authored andcommitted
add file header and cleanup profiles e2e tests
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 5edd783 commit 707d55c

File tree

2 files changed

+54
-33
lines changed

2 files changed

+54
-33
lines changed

pkg/e2e/fixtures/profiles/compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
2-
main:
2+
regular-service:
33
image: nginx:alpine
44

55
profiled-service:

pkg/e2e/profiles_test.go

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package e2e
218

319
import (
4-
"gotest.tools/v3/assert"
5-
"gotest.tools/v3/icmd"
620
"strings"
721
"testing"
22+
23+
"gotest.tools/v3/assert"
24+
"gotest.tools/v3/icmd"
25+
)
26+
27+
const (
28+
profiledService = "profiled-service"
29+
regularService = "regular-service"
830
)
931

1032
func TestExplicitProfileUsage(t *testing.T) {
@@ -17,35 +39,35 @@ func TestExplicitProfileUsage(t *testing.T) {
1739
"-p", projectName, "--profile", profileName, "up", "-d")
1840
res.Assert(t, icmd.Expected{ExitCode: 0})
1941
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
20-
res.Assert(t, icmd.Expected{Out: "profiled-service"})
21-
res.Assert(t, icmd.Expected{Out: "main"})
42+
res.Assert(t, icmd.Expected{Out: regularService})
43+
res.Assert(t, icmd.Expected{Out: profiledService})
2244
})
2345

2446
t.Run("compose stop with profile", func(t *testing.T) {
2547
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
2648
"-p", projectName, "--profile", profileName, "stop")
2749
res.Assert(t, icmd.Expected{ExitCode: 0})
2850
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
29-
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
30-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
51+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
52+
assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
3153
})
3254

3355
t.Run("compose start with profile", func(t *testing.T) {
3456
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
3557
"-p", projectName, "--profile", profileName, "start")
3658
res.Assert(t, icmd.Expected{ExitCode: 0})
3759
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
38-
res.Assert(t, icmd.Expected{Out: "profiled-service"})
39-
res.Assert(t, icmd.Expected{Out: "main"})
60+
res.Assert(t, icmd.Expected{Out: regularService})
61+
res.Assert(t, icmd.Expected{Out: profiledService})
4062
})
4163

4264
t.Run("compose restart with profile", func(t *testing.T) {
4365
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
4466
"-p", projectName, "--profile", profileName, "restart")
4567
res.Assert(t, icmd.Expected{ExitCode: 0})
4668
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
47-
res.Assert(t, icmd.Expected{Out: "profiled-service"})
48-
res.Assert(t, icmd.Expected{Out: "main"})
69+
res.Assert(t, icmd.Expected{Out: regularService})
70+
res.Assert(t, icmd.Expected{Out: profiledService})
4971
})
5072

5173
t.Run("down", func(t *testing.T) {
@@ -67,35 +89,35 @@ func TestNoProfileUsage(t *testing.T) {
6789
"-p", projectName, "up", "-d")
6890
res.Assert(t, icmd.Expected{ExitCode: 0})
6991
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
70-
res.Assert(t, icmd.Expected{Out: "main"})
71-
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
92+
res.Assert(t, icmd.Expected{Out: regularService})
93+
assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
7294
})
7395

7496
t.Run("compose stop without profile", func(t *testing.T) {
7597
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
7698
"-p", projectName, "stop")
7799
res.Assert(t, icmd.Expected{ExitCode: 0})
78100
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
79-
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
80-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
101+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
102+
assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
81103
})
82104

83105
t.Run("compose start without profile", func(t *testing.T) {
84106
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
85107
"-p", projectName, "start")
86108
res.Assert(t, icmd.Expected{ExitCode: 0})
87109
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
88-
res.Assert(t, icmd.Expected{Out: "main"})
89-
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
110+
res.Assert(t, icmd.Expected{Out: regularService})
111+
assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
90112
})
91113

92114
t.Run("compose restart without profile", func(t *testing.T) {
93115
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
94116
"-p", projectName, "restart")
95117
res.Assert(t, icmd.Expected{ExitCode: 0})
96118
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
97-
res.Assert(t, icmd.Expected{Out: "main"})
98-
assert.Assert(t, !strings.Contains(res.Combined(), "profiled-service"))
119+
res.Assert(t, icmd.Expected{Out: regularService})
120+
assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
99121
})
100122

101123
t.Run("down", func(t *testing.T) {
@@ -112,47 +134,46 @@ func TestActiveProfileViaTargetedService(t *testing.T) {
112134
c := NewParallelCLI(t)
113135
const projectName = "compose-e2e-profiles-via-target-service"
114136
const profileName = "test-profile"
115-
const targetedService = "profiled-service"
116137

117138
t.Run("compose up with service name", func(t *testing.T) {
118139
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
119-
"-p", projectName, "up", targetedService, "-d")
140+
"-p", projectName, "up", profiledService, "-d")
120141
res.Assert(t, icmd.Expected{ExitCode: 0})
121142

122143
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps")
123-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
124-
res.Assert(t, icmd.Expected{Out: targetedService})
144+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
145+
res.Assert(t, icmd.Expected{Out: profiledService})
125146

126147
res = c.RunDockerComposeCmd(t, "-p", projectName, "--profile", profileName, "ps")
127-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
128-
res.Assert(t, icmd.Expected{Out: targetedService})
148+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
149+
res.Assert(t, icmd.Expected{Out: profiledService})
129150
})
130151

131152
t.Run("compose stop with service name", func(t *testing.T) {
132153
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
133-
"-p", projectName, "stop", targetedService)
154+
"-p", projectName, "stop", profiledService)
134155
res.Assert(t, icmd.Expected{ExitCode: 0})
135156
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
136-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
137-
assert.Assert(t, !strings.Contains(res.Combined(), targetedService))
157+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
158+
assert.Assert(t, !strings.Contains(res.Combined(), profiledService))
138159
})
139160

140161
t.Run("compose start with service name", func(t *testing.T) {
141162
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
142-
"-p", projectName, "start", targetedService)
163+
"-p", projectName, "start", profiledService)
143164
res.Assert(t, icmd.Expected{ExitCode: 0})
144165
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
145-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
146-
res.Assert(t, icmd.Expected{Out: targetedService})
166+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
167+
res.Assert(t, icmd.Expected{Out: profiledService})
147168
})
148169

149170
t.Run("compose restart with service name", func(t *testing.T) {
150171
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/profiles/compose.yaml",
151172
"-p", projectName, "restart")
152173
res.Assert(t, icmd.Expected{ExitCode: 0})
153174
res = c.RunDockerComposeCmd(t, "-p", projectName, "ps", "--status", "running")
154-
assert.Assert(t, !strings.Contains(res.Combined(), "main"))
155-
res.Assert(t, icmd.Expected{Out: targetedService})
175+
assert.Assert(t, !strings.Contains(res.Combined(), regularService))
176+
res.Assert(t, icmd.Expected{Out: profiledService})
156177
})
157178

158179
t.Run("down", func(t *testing.T) {

0 commit comments

Comments
 (0)