@@ -376,3 +376,92 @@ func TestGetHostListItems(t *testing.T) {
376376 }
377377 }
378378}
379+
380+ // issue #1908
381+ func TestGetHostListItemsEnvDockerHostUnset (t * testing.T ) {
382+ orgDockerHost := os .Getenv ("DOCKER_HOST" )
383+ defer func () {
384+ cleanup ()
385+
386+ // revert DOCKER_HOST
387+ os .Setenv ("DOCKER_HOST" , orgDockerHost )
388+ }()
389+
390+ // unset DOCKER_HOST
391+ os .Unsetenv ("DOCKER_HOST" )
392+
393+ hostListItemsChan := make (chan HostListItem )
394+
395+ hosts := []* host.Host {
396+ {
397+ Name : "foo" ,
398+ DriverName : "fakedriver" ,
399+ Driver : & fakedriver.FakeDriver {
400+ MockState : state .Running ,
401+ MockURL : "tcp://120.0.0.1:2376" ,
402+ },
403+ HostOptions : & host.HostOptions {
404+ SwarmOptions : & swarm.SwarmOptions {
405+ Master : false ,
406+ Address : "" ,
407+ Discovery : "" ,
408+ },
409+ },
410+ },
411+ {
412+ Name : "bar" ,
413+ DriverName : "fakedriver" ,
414+ Driver : & fakedriver.FakeDriver {
415+ MockState : state .Stopped ,
416+ },
417+ HostOptions : & host.HostOptions {
418+ SwarmOptions : & swarm.SwarmOptions {
419+ Master : false ,
420+ Address : "" ,
421+ Discovery : "" ,
422+ },
423+ },
424+ },
425+ {
426+ Name : "baz" ,
427+ DriverName : "fakedriver" ,
428+ Driver : & fakedriver.FakeDriver {
429+ MockState : state .Saved ,
430+ },
431+ HostOptions : & host.HostOptions {
432+ SwarmOptions : & swarm.SwarmOptions {
433+ Master : false ,
434+ Address : "" ,
435+ Discovery : "" ,
436+ },
437+ },
438+ },
439+ }
440+
441+ expected := map [string ]struct {
442+ state state.State
443+ active bool
444+ }{
445+ "foo" : {state .Running , false },
446+ "bar" : {state .Stopped , false },
447+ "baz" : {state .Saved , false },
448+ }
449+
450+ items := []HostListItem {}
451+ for _ , host := range hosts {
452+ go getHostState (host , hostListItemsChan )
453+ }
454+
455+ for i := 0 ; i < len (hosts ); i ++ {
456+ items = append (items , <- hostListItemsChan )
457+ }
458+
459+ for _ , item := range items {
460+ if expected [item .Name ].state != item .State {
461+ t .Fatal ("Expected state did not match for item" , item )
462+ }
463+ if expected [item .Name ].active != item .Active {
464+ t .Fatal ("Expected active flag did not match for item" , item )
465+ }
466+ }
467+ }
0 commit comments