@@ -277,10 +277,20 @@ func TestBundle(t *testing.T) {
277277}
278278
279279func 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+ })
286+ }
287+
288+ func testDockerAppLifecycle (t * testing.T , useBindMount bool ) {
280289 cmd , cleanup := dockerCli .createTestCmd ()
281290 defer cleanup ()
291+ appName := strings .Replace (t .Name (), "/" , "_" , 1 )
282292
283- tmpDir := fs .NewDir (t , t . Name () )
293+ tmpDir := fs .NewDir (t , appName )
284294 defer tmpDir .Remove ()
285295
286296 cmd .Env = append (cmd .Env , "DUFFLE_HOME=" + tmpDir .Path ())
@@ -306,7 +316,12 @@ func TestDockerAppLifecycle(t *testing.T) {
306316 // The workaround is to create a context with an empty host.
307317 // This host will default to the unix socket inside the
308318 // invocation image
309- cmd .Command = dockerCli .Command ("context" , "create" , "swarm-target-context" , "--docker" , "host=" , "--default-stack-orchestrator" , "swarm" )
319+ host := "host="
320+ if ! useBindMount {
321+ host += fmt .Sprintf ("tcp://%s" , swarm .GetPrivateAddress (t ))
322+ }
323+
324+ cmd .Command = dockerCli .Command ("context" , "create" , "swarm-target-context" , "--docker" , host , "--default-stack-orchestrator" , "swarm" )
310325 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
311326
312327 // Initialize the swarm
@@ -319,47 +334,47 @@ func TestDockerAppLifecycle(t *testing.T) {
319334 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
320335
321336 // Install a Docker Application Package
322- 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 )
323338 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
324339 []string {
325- fmt .Sprintf ("Creating network %s_back" , t . Name () ),
326- fmt .Sprintf ("Creating network %s_front" , t . Name () ),
327- fmt .Sprintf ("Creating service %s_db" , t . Name () ),
328- fmt .Sprintf ("Creating service %s_api" , t . Name () ),
329- 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 ),
330345 })
331346
332347 // Query the application status
333- cmd .Command = dockerCli .Command ("app" , "status" , t . Name () )
348+ cmd .Command = dockerCli .Command ("app" , "status" , appName )
334349 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
335350 []string {
336- fmt .Sprintf ("[[:alnum:]]+ %s_db replicated [0-1]/1 postgres:9.3" , t . Name () ),
337- fmt .Sprintf (`[[:alnum:]]+ %s_web replicated [0-1]/1 nginx:latest \*:8082->80/tcp` , t . Name () ),
338- 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 ),
339354 })
340355
341356 // Upgrade the application, changing the port
342- cmd .Command = dockerCli .Command ("app" , "upgrade" , t . Name () , "--set" , "web_port=8081" )
357+ cmd .Command = dockerCli .Command ("app" , "upgrade" , appName , "--set" , "web_port=8081" )
343358 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
344359 []string {
345- fmt .Sprintf ("Updating service %s_db" , t . Name () ),
346- fmt .Sprintf ("Updating service %s_api" , t . Name () ),
347- 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 ),
348363 })
349364
350365 // Query the application status again, the port should have change
351- cmd .Command = dockerCli .Command ("app" , "status" , t . Name () )
366+ cmd .Command = dockerCli .Command ("app" , "status" , appName )
352367 icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 0 , Out : "8081" })
353368
354369 // Uninstall the application
355- cmd .Command = dockerCli .Command ("app" , "uninstall" , t . Name () )
370+ cmd .Command = dockerCli .Command ("app" , "uninstall" , appName )
356371 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
357372 []string {
358- fmt .Sprintf ("Removing service %s_api" , t . Name () ),
359- fmt .Sprintf ("Removing service %s_db" , t . Name () ),
360- fmt .Sprintf ("Removing service %s_web" , t . Name () ),
361- fmt .Sprintf ("Removing network %s_front" , t . Name () ),
362- 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 ),
363378 })
364379}
365380
0 commit comments