@@ -276,19 +276,21 @@ func TestBundle(t *testing.T) {
276276 assert .Assert (t , fs .Equal (tmpDir .Join ("simple.dockerapp" ), manifest ))
277277}
278278
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+ })
285286}
286287
287288func testDockerAppLifecycle (t * testing.T , useBindMount bool ) {
288289 cmd , cleanup := dockerCli .createTestCmd ()
289290 defer cleanup ()
291+ appName := strings .Replace (t .Name (), "/" , "_" , 1 )
290292
291- tmpDir := fs .NewDir (t , t . Name () )
293+ tmpDir := fs .NewDir (t , appName )
292294 defer tmpDir .Remove ()
293295
294296 cmd .Env = append (cmd .Env , "DUFFLE_HOME=" + tmpDir .Path ())
@@ -309,19 +311,19 @@ func testDockerAppLifecycle(t *testing.T, useBindMount bool) {
309311 cmd .Command = dockerCli .Command ("context" , "create" , "swarm-context" , "--docker" , fmt .Sprintf (`"host=tcp://%s"` , swarm .GetAddress (t )), "--default-stack-orchestrator" , "swarm" )
310312 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
311313
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 ))
323322 }
324323
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+
325327 // Initialize the swarm
326328 cmd .Env = append (cmd .Env , "DOCKER_CONTEXT=swarm-context" )
327329 cmd .Command = dockerCli .Command ("swarm" , "init" )
@@ -332,47 +334,47 @@ func testDockerAppLifecycle(t *testing.T, useBindMount bool) {
332334 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
333335
334336 // 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 )
336338 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
337339 []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 ),
343345 })
344346
345347 // Query the application status
346- cmd .Command = dockerCli .Command ("app" , "status" , t . Name () )
348+ cmd .Command = dockerCli .Command ("app" , "status" , appName )
347349 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
348350 []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 ),
352354 })
353355
354356 // 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" )
356358 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
357359 []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 ),
361363 })
362364
363365 // 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 )
365367 icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 0 , Out : "8081" })
366368
367369 // Uninstall the application
368- cmd .Command = dockerCli .Command ("app" , "uninstall" , t . Name () )
370+ cmd .Command = dockerCli .Command ("app" , "uninstall" , appName )
369371 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
370372 []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 ),
376378 })
377379}
378380
0 commit comments