@@ -23,6 +23,7 @@ import (
23
23
24
24
testify "github.com/stretchr/testify/assert"
25
25
"gotest.tools/v3/assert"
26
+ "gotest.tools/v3/icmd"
26
27
)
27
28
28
29
func TestStartStop (t * testing.T ) {
@@ -182,3 +183,66 @@ func TestStartStopWithOneOffs(t *testing.T) {
182
183
assert .Assert (t , ! strings .Contains (res .Combined (), "e2e-start-stop-with-oneoffs-bar" ), res .Combined ())
183
184
})
184
185
}
186
+
187
+ func TestStartAlreadyRunning (t * testing.T ) {
188
+ cli := NewParallelCLI (t , WithEnv (
189
+ "COMPOSE_PROJECT_NAME=e2e-start-stop-svc-already-running" ,
190
+ "COMPOSE_FILE=./fixtures/start-stop/compose.yaml" ))
191
+ t .Cleanup (func () {
192
+ cli .RunDockerComposeCmd (t , "down" , "--remove-orphans" , "-v" , "-t" , "0" )
193
+ })
194
+
195
+ cli .RunDockerComposeCmd (t , "up" , "-d" , "--wait" )
196
+
197
+ res := cli .RunDockerComposeCmd (t , "start" , "simple" )
198
+ assert .Equal (t , res .Stdout (), "" , "No output should have been written to stdout" )
199
+ }
200
+
201
+ func TestStopAlreadyStopped (t * testing.T ) {
202
+ cli := NewParallelCLI (t , WithEnv (
203
+ "COMPOSE_PROJECT_NAME=e2e-start-stop-svc-already-stopped" ,
204
+ "COMPOSE_FILE=./fixtures/start-stop/compose.yaml" ))
205
+ t .Cleanup (func () {
206
+ cli .RunDockerComposeCmd (t , "down" , "--remove-orphans" , "-v" , "-t" , "0" )
207
+ })
208
+
209
+ cli .RunDockerComposeCmd (t , "up" , "-d" , "--wait" )
210
+
211
+ // stop the container
212
+ cli .RunDockerComposeCmd (t , "stop" , "simple" )
213
+
214
+ // attempt to stop it again
215
+ res := cli .RunDockerComposeCmdNoCheck (t , "stop" , "simple" )
216
+ // TODO: for consistency, this should NOT write any output because the
217
+ // container is already stopped
218
+ res .Assert (t , icmd.Expected {
219
+ ExitCode : 0 ,
220
+ Err : "Container e2e-start-stop-svc-already-stopped-simple-1 Stopped" ,
221
+ })
222
+ }
223
+
224
+ func TestStartStopMultipleServices (t * testing.T ) {
225
+ cli := NewParallelCLI (t , WithEnv (
226
+ "COMPOSE_PROJECT_NAME=e2e-start-stop-svc-multiple" ,
227
+ "COMPOSE_FILE=./fixtures/start-stop/compose.yaml" ))
228
+ t .Cleanup (func () {
229
+ cli .RunDockerComposeCmd (t , "down" , "--remove-orphans" , "-v" , "-t" , "0" )
230
+ })
231
+
232
+ cli .RunDockerComposeCmd (t , "up" , "-d" , "--wait" )
233
+
234
+ res := cli .RunDockerComposeCmd (t , "stop" , "simple" , "another" )
235
+ services := []string {"simple" , "another" }
236
+ for _ , svc := range services {
237
+ stopMsg := fmt .Sprintf ("Container e2e-start-stop-svc-multiple-%s-1 Stopped" , svc )
238
+ assert .Assert (t , strings .Contains (res .Stderr (), stopMsg ),
239
+ fmt .Sprintf ("Missing stop message for %s\n %s" , svc , res .Combined ()))
240
+ }
241
+
242
+ res = cli .RunDockerComposeCmd (t , "start" , "simple" , "another" )
243
+ for _ , svc := range services {
244
+ startMsg := fmt .Sprintf ("Container e2e-start-stop-svc-multiple-%s-1 Started" , svc )
245
+ assert .Assert (t , strings .Contains (res .Stderr (), startMsg ),
246
+ fmt .Sprintf ("Missing start message for %s\n %s" , svc , res .Combined ()))
247
+ }
248
+ }
0 commit comments