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
+
1
17
package e2e
2
18
3
19
import (
4
- "gotest.tools/v3/assert"
5
- "gotest.tools/v3/icmd"
6
20
"strings"
7
21
"testing"
22
+
23
+ "gotest.tools/v3/assert"
24
+ "gotest.tools/v3/icmd"
25
+ )
26
+
27
+ const (
28
+ profiledService = "profiled-service"
29
+ regularService = "regular-service"
8
30
)
9
31
10
32
func TestExplicitProfileUsage (t * testing.T ) {
@@ -17,35 +39,35 @@ func TestExplicitProfileUsage(t *testing.T) {
17
39
"-p" , projectName , "--profile" , profileName , "up" , "-d" )
18
40
res .Assert (t , icmd.Expected {ExitCode : 0 })
19
41
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 })
22
44
})
23
45
24
46
t .Run ("compose stop with profile" , func (t * testing.T ) {
25
47
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
26
48
"-p" , projectName , "--profile" , profileName , "stop" )
27
49
res .Assert (t , icmd.Expected {ExitCode : 0 })
28
50
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 ))
31
53
})
32
54
33
55
t .Run ("compose start with profile" , func (t * testing.T ) {
34
56
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
35
57
"-p" , projectName , "--profile" , profileName , "start" )
36
58
res .Assert (t , icmd.Expected {ExitCode : 0 })
37
59
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 })
40
62
})
41
63
42
64
t .Run ("compose restart with profile" , func (t * testing.T ) {
43
65
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
44
66
"-p" , projectName , "--profile" , profileName , "restart" )
45
67
res .Assert (t , icmd.Expected {ExitCode : 0 })
46
68
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 })
49
71
})
50
72
51
73
t .Run ("down" , func (t * testing.T ) {
@@ -67,35 +89,35 @@ func TestNoProfileUsage(t *testing.T) {
67
89
"-p" , projectName , "up" , "-d" )
68
90
res .Assert (t , icmd.Expected {ExitCode : 0 })
69
91
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 ))
72
94
})
73
95
74
96
t .Run ("compose stop without profile" , func (t * testing.T ) {
75
97
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
76
98
"-p" , projectName , "stop" )
77
99
res .Assert (t , icmd.Expected {ExitCode : 0 })
78
100
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 ))
81
103
})
82
104
83
105
t .Run ("compose start without profile" , func (t * testing.T ) {
84
106
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
85
107
"-p" , projectName , "start" )
86
108
res .Assert (t , icmd.Expected {ExitCode : 0 })
87
109
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 ))
90
112
})
91
113
92
114
t .Run ("compose restart without profile" , func (t * testing.T ) {
93
115
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
94
116
"-p" , projectName , "restart" )
95
117
res .Assert (t , icmd.Expected {ExitCode : 0 })
96
118
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 ))
99
121
})
100
122
101
123
t .Run ("down" , func (t * testing.T ) {
@@ -112,47 +134,46 @@ func TestActiveProfileViaTargetedService(t *testing.T) {
112
134
c := NewParallelCLI (t )
113
135
const projectName = "compose-e2e-profiles-via-target-service"
114
136
const profileName = "test-profile"
115
- const targetedService = "profiled-service"
116
137
117
138
t .Run ("compose up with service name" , func (t * testing.T ) {
118
139
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
119
- "-p" , projectName , "up" , targetedService , "-d" )
140
+ "-p" , projectName , "up" , profiledService , "-d" )
120
141
res .Assert (t , icmd.Expected {ExitCode : 0 })
121
142
122
143
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 })
125
146
126
147
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 })
129
150
})
130
151
131
152
t .Run ("compose stop with service name" , func (t * testing.T ) {
132
153
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
133
- "-p" , projectName , "stop" , targetedService )
154
+ "-p" , projectName , "stop" , profiledService )
134
155
res .Assert (t , icmd.Expected {ExitCode : 0 })
135
156
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 ))
138
159
})
139
160
140
161
t .Run ("compose start with service name" , func (t * testing.T ) {
141
162
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
142
- "-p" , projectName , "start" , targetedService )
163
+ "-p" , projectName , "start" , profiledService )
143
164
res .Assert (t , icmd.Expected {ExitCode : 0 })
144
165
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 })
147
168
})
148
169
149
170
t .Run ("compose restart with service name" , func (t * testing.T ) {
150
171
res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
151
172
"-p" , projectName , "restart" )
152
173
res .Assert (t , icmd.Expected {ExitCode : 0 })
153
174
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 })
156
177
})
157
178
158
179
t .Run ("down" , func (t * testing.T ) {
0 commit comments