@@ -276,19 +276,21 @@ func TestBundle(t *testing.T) {
276
276
assert .Assert (t , fs .Equal (tmpDir .Join ("simple.dockerapp" ), manifest ))
277
277
}
278
278
279
- func TestDockerAppLifecycleWithBindMounts (t * testing.T ) {
280
- testDockerAppLifecycle (t , true )
281
- }
282
-
283
- func TestDockerAppLifecycleWithoutBindMounts (t * testing.T ) {
284
- testDockerAppLifecycle (t , false )
279
+ func TestDockerAppLifecycle (t * testing.T ) {
280
+ t .Run ("withBindMounts" , func (t * testing.T ) {
281
+ testDockerAppLifecycle (t , true )
282
+ })
283
+ t .Run ("withoutBindMounts" , func (t * testing.T ) {
284
+ testDockerAppLifecycle (t , false )
285
+ })
285
286
}
286
287
287
288
func testDockerAppLifecycle (t * testing.T , useBindMount bool ) {
288
289
cmd , cleanup := dockerCli .createTestCmd ()
289
290
defer cleanup ()
291
+ appName := strings .Replace (t .Name (), "/" , "_" , 1 )
290
292
291
- tmpDir := fs .NewDir (t , t . Name () )
293
+ tmpDir := fs .NewDir (t , appName )
292
294
defer tmpDir .Remove ()
293
295
294
296
cmd .Env = append (cmd .Env , "DUFFLE_HOME=" + tmpDir .Path ())
@@ -309,19 +311,19 @@ func testDockerAppLifecycle(t *testing.T, useBindMount bool) {
309
311
cmd .Command = dockerCli .Command ("context" , "create" , "swarm-context" , "--docker" , fmt .Sprintf (`"host=tcp://%s"` , swarm .GetAddress (t )), "--default-stack-orchestrator" , "swarm" )
310
312
icmd .RunCmd (cmd ).Assert (t , icmd .Success )
311
313
312
- if useBindMount {
313
- // When creating a context on a Windows host we cannot use
314
- // the unix socket but it's needed inside the invocation image.
315
- // The workaround is to create a context with an empty host.
316
- // This host will default to the unix socket inside the
317
- // invocation image
318
- cmd .Command = dockerCli .Command ("context" , "create" , "swarm-target-context" , "--docker" , "host=" , "--default-stack-orchestrator" , "swarm" )
319
- icmd .RunCmd (cmd ).Assert (t , icmd .Success )
320
- } else {
321
- cmd .Command = dockerCli .Command ("context" , "create" , "swarm-target-context" , "--docker" , fmt .Sprintf (`"host=tcp://%s"` , swarm .GetPrivateAddress (t )), "--default-stack-orchestrator" , "swarm" )
322
- icmd .RunCmd (cmd ).Assert (t , icmd .Success )
314
+ // When creating a context on a Windows host we cannot use
315
+ // the unix socket but it's needed inside the invocation image.
316
+ // The workaround is to create a context with an empty host.
317
+ // This host will default to the unix socket inside the
318
+ // invocation image
319
+ host := "host="
320
+ if ! useBindMount {
321
+ host += fmt .Sprintf ("tcp://%s" , swarm .GetPrivateAddress (t ))
323
322
}
324
323
324
+ cmd .Command = dockerCli .Command ("context" , "create" , "swarm-target-context" , "--docker" , host , "--default-stack-orchestrator" , "swarm" )
325
+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
326
+
325
327
// Initialize the swarm
326
328
cmd .Env = append (cmd .Env , "DOCKER_CONTEXT=swarm-context" )
327
329
cmd .Command = dockerCli .Command ("swarm" , "init" )
@@ -332,47 +334,47 @@ func testDockerAppLifecycle(t *testing.T, useBindMount bool) {
332
334
icmd .RunCmd (cmd ).Assert (t , icmd .Success )
333
335
334
336
// Install a Docker Application Package
335
- cmd .Command = dockerCli .Command ("app" , "install" , "testdata/simple/simple.dockerapp" , "--name" , t . Name () )
337
+ cmd .Command = dockerCli .Command ("app" , "install" , "testdata/simple/simple.dockerapp" , "--name" , appName )
336
338
checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
337
339
[]string {
338
- fmt .Sprintf ("Creating network %s_back" , t . Name () ),
339
- fmt .Sprintf ("Creating network %s_front" , t . Name () ),
340
- fmt .Sprintf ("Creating service %s_db" , t . Name () ),
341
- fmt .Sprintf ("Creating service %s_api" , t . Name () ),
342
- fmt .Sprintf ("Creating service %s_web" , t . Name () ),
340
+ fmt .Sprintf ("Creating network %s_back" , appName ),
341
+ fmt .Sprintf ("Creating network %s_front" , appName ),
342
+ fmt .Sprintf ("Creating service %s_db" , appName ),
343
+ fmt .Sprintf ("Creating service %s_api" , appName ),
344
+ fmt .Sprintf ("Creating service %s_web" , appName ),
343
345
})
344
346
345
347
// Query the application status
346
- cmd .Command = dockerCli .Command ("app" , "status" , t . Name () )
348
+ cmd .Command = dockerCli .Command ("app" , "status" , appName )
347
349
checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
348
350
[]string {
349
- fmt .Sprintf ("[[:alnum:]]+ %s_db replicated [0-1]/1 postgres:9.3" , t . Name () ),
350
- fmt .Sprintf (`[[:alnum:]]+ %s_web replicated [0-1]/1 nginx:latest \*:8082->80/tcp` , t . Name () ),
351
- fmt .Sprintf ("[[:alnum:]]+ %s_api replicated [0-1]/1 python:3.6" , t . Name () ),
351
+ fmt .Sprintf ("[[:alnum:]]+ %s_db replicated [0-1]/1 postgres:9.3" , appName ),
352
+ fmt .Sprintf (`[[:alnum:]]+ %s_web replicated [0-1]/1 nginx:latest \*:8082->80/tcp` , appName ),
353
+ fmt .Sprintf ("[[:alnum:]]+ %s_api replicated [0-1]/1 python:3.6" , appName ),
352
354
})
353
355
354
356
// Upgrade the application, changing the port
355
- cmd .Command = dockerCli .Command ("app" , "upgrade" , t . Name () , "--set" , "web_port=8081" )
357
+ cmd .Command = dockerCli .Command ("app" , "upgrade" , appName , "--set" , "web_port=8081" )
356
358
checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
357
359
[]string {
358
- fmt .Sprintf ("Updating service %s_db" , t . Name () ),
359
- fmt .Sprintf ("Updating service %s_api" , t . Name () ),
360
- fmt .Sprintf ("Updating service %s_web" , t . Name () ),
360
+ fmt .Sprintf ("Updating service %s_db" , appName ),
361
+ fmt .Sprintf ("Updating service %s_api" , appName ),
362
+ fmt .Sprintf ("Updating service %s_web" , appName ),
361
363
})
362
364
363
365
// Query the application status again, the port should have change
364
- cmd .Command = dockerCli .Command ("app" , "status" , t . Name () )
366
+ cmd .Command = dockerCli .Command ("app" , "status" , appName )
365
367
icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 0 , Out : "8081" })
366
368
367
369
// Uninstall the application
368
- cmd .Command = dockerCli .Command ("app" , "uninstall" , t . Name () )
370
+ cmd .Command = dockerCli .Command ("app" , "uninstall" , appName )
369
371
checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
370
372
[]string {
371
- fmt .Sprintf ("Removing service %s_api" , t . Name () ),
372
- fmt .Sprintf ("Removing service %s_db" , t . Name () ),
373
- fmt .Sprintf ("Removing service %s_web" , t . Name () ),
374
- fmt .Sprintf ("Removing network %s_front" , t . Name () ),
375
- fmt .Sprintf ("Removing network %s_back" , t . Name () ),
373
+ fmt .Sprintf ("Removing service %s_api" , appName ),
374
+ fmt .Sprintf ("Removing service %s_db" , appName ),
375
+ fmt .Sprintf ("Removing service %s_web" , appName ),
376
+ fmt .Sprintf ("Removing network %s_front" , appName ),
377
+ fmt .Sprintf ("Removing network %s_back" , appName ),
376
378
})
377
379
}
378
380
0 commit comments