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+
117package e2e
218
319import (
@@ -7,6 +23,11 @@ import (
723 "testing"
824)
925
26+ const (
27+ profiledService = "profiled-service"
28+ regularService = "regular-service"
29+ )
30+
1031func TestExplicitProfileUsage (t * testing.T ) {
1132 c := NewParallelCLI (t )
1233 const projectName = "compose-e2e-profiles"
@@ -17,35 +38,35 @@ func TestExplicitProfileUsage(t *testing.T) {
1738 "-p" , projectName , "--profile" , profileName , "up" , "-d" )
1839 res .Assert (t , icmd.Expected {ExitCode : 0 })
1940 res = c .RunDockerComposeCmd (t , "-p" , projectName , "ps" )
20- res .Assert (t , icmd.Expected {Out : "profiled-service" })
21- res .Assert (t , icmd.Expected {Out : "main" })
41+ res .Assert (t , icmd.Expected {Out : regularService })
42+ res .Assert (t , icmd.Expected {Out : profiledService })
2243 })
2344
2445 t .Run ("compose stop with profile" , func (t * testing.T ) {
2546 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
2647 "-p" , projectName , "--profile" , profileName , "stop" )
2748 res .Assert (t , icmd.Expected {ExitCode : 0 })
2849 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" ))
50+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
51+ assert .Assert (t , ! strings .Contains (res .Combined (), profiledService ))
3152 })
3253
3354 t .Run ("compose start with profile" , func (t * testing.T ) {
3455 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
3556 "-p" , projectName , "--profile" , profileName , "start" )
3657 res .Assert (t , icmd.Expected {ExitCode : 0 })
3758 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" })
59+ res .Assert (t , icmd.Expected {Out : regularService })
60+ res .Assert (t , icmd.Expected {Out : profiledService })
4061 })
4162
4263 t .Run ("compose restart with profile" , func (t * testing.T ) {
4364 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
4465 "-p" , projectName , "--profile" , profileName , "restart" )
4566 res .Assert (t , icmd.Expected {ExitCode : 0 })
4667 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" })
68+ res .Assert (t , icmd.Expected {Out : regularService })
69+ res .Assert (t , icmd.Expected {Out : profiledService })
4970 })
5071
5172 t .Run ("down" , func (t * testing.T ) {
@@ -67,35 +88,35 @@ func TestNoProfileUsage(t *testing.T) {
6788 "-p" , projectName , "up" , "-d" )
6889 res .Assert (t , icmd.Expected {ExitCode : 0 })
6990 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" ))
91+ res .Assert (t , icmd.Expected {Out : regularService })
92+ assert .Assert (t , ! strings .Contains (res .Combined (), profiledService ))
7293 })
7394
7495 t .Run ("compose stop without profile" , func (t * testing.T ) {
7596 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
7697 "-p" , projectName , "stop" )
7798 res .Assert (t , icmd.Expected {ExitCode : 0 })
7899 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" ))
100+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
101+ assert .Assert (t , ! strings .Contains (res .Combined (), profiledService ))
81102 })
82103
83104 t .Run ("compose start without profile" , func (t * testing.T ) {
84105 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
85106 "-p" , projectName , "start" )
86107 res .Assert (t , icmd.Expected {ExitCode : 0 })
87108 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" ))
109+ res .Assert (t , icmd.Expected {Out : regularService })
110+ assert .Assert (t , ! strings .Contains (res .Combined (), profiledService ))
90111 })
91112
92113 t .Run ("compose restart without profile" , func (t * testing.T ) {
93114 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
94115 "-p" , projectName , "restart" )
95116 res .Assert (t , icmd.Expected {ExitCode : 0 })
96117 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" ))
118+ res .Assert (t , icmd.Expected {Out : regularService })
119+ assert .Assert (t , ! strings .Contains (res .Combined (), profiledService ))
99120 })
100121
101122 t .Run ("down" , func (t * testing.T ) {
@@ -112,47 +133,46 @@ func TestActiveProfileViaTargetedService(t *testing.T) {
112133 c := NewParallelCLI (t )
113134 const projectName = "compose-e2e-profiles-via-target-service"
114135 const profileName = "test-profile"
115- const targetedService = "profiled-service"
116136
117137 t .Run ("compose up with service name" , func (t * testing.T ) {
118138 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
119- "-p" , projectName , "up" , targetedService , "-d" )
139+ "-p" , projectName , "up" , profiledService , "-d" )
120140 res .Assert (t , icmd.Expected {ExitCode : 0 })
121141
122142 res = c .RunDockerComposeCmd (t , "-p" , projectName , "ps" )
123- assert .Assert (t , ! strings .Contains (res .Combined (), "main" ))
124- res .Assert (t , icmd.Expected {Out : targetedService })
143+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
144+ res .Assert (t , icmd.Expected {Out : profiledService })
125145
126146 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 })
147+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
148+ res .Assert (t , icmd.Expected {Out : profiledService })
129149 })
130150
131151 t .Run ("compose stop with service name" , func (t * testing.T ) {
132152 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
133- "-p" , projectName , "stop" , targetedService )
153+ "-p" , projectName , "stop" , profiledService )
134154 res .Assert (t , icmd.Expected {ExitCode : 0 })
135155 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 ))
156+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
157+ assert .Assert (t , ! strings .Contains (res .Combined (), profiledService ))
138158 })
139159
140160 t .Run ("compose start with service name" , func (t * testing.T ) {
141161 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
142- "-p" , projectName , "start" , targetedService )
162+ "-p" , projectName , "start" , profiledService )
143163 res .Assert (t , icmd.Expected {ExitCode : 0 })
144164 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 })
165+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
166+ res .Assert (t , icmd.Expected {Out : profiledService })
147167 })
148168
149169 t .Run ("compose restart with service name" , func (t * testing.T ) {
150170 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/profiles/compose.yaml" ,
151171 "-p" , projectName , "restart" )
152172 res .Assert (t , icmd.Expected {ExitCode : 0 })
153173 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 })
174+ assert .Assert (t , ! strings .Contains (res .Combined (), regularService ))
175+ res .Assert (t , icmd.Expected {Out : profiledService })
156176 })
157177
158178 t .Run ("down" , func (t * testing.T ) {
0 commit comments