github.com/mponton/terratest@v0.44.0/modules/docker/host_test.go (about) 1 package docker 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestGetDockerHostFromEnv(t *testing.T) { 11 12 t.Parallel() 13 14 tests := []struct { 15 Input string 16 Expected string 17 }{ 18 { 19 "unix:///var/run/docker.sock", 20 "localhost", 21 }, 22 { 23 "npipe:////./pipe/docker_engine", 24 "localhost", 25 }, 26 { 27 "tcp://1.2.3.4:1234", 28 "1.2.3.4", 29 }, 30 { 31 "tcp://1.2.3.4", 32 "1.2.3.4", 33 }, 34 { 35 "ssh://1.2.3.4:22", 36 "1.2.3.4", 37 }, 38 { 39 "fd://1.2.3.4:1234", 40 "1.2.3.4", 41 }, 42 { 43 "", 44 "localhost", 45 }, 46 { 47 "invalidValue", 48 "localhost", 49 }, 50 { 51 "invalid::value::with::semicolons", 52 "localhost", 53 }, 54 } 55 for _, test := range tests { 56 t.Run(fmt.Sprintf("GetDockerHostFromEnv: %s", test.Input), func(t *testing.T) { 57 t.Parallel() 58 59 testEnv := []string{ 60 "FOO=bar", 61 fmt.Sprintf("DOCKER_HOST=%s", test.Input), 62 "BAR=baz", 63 } 64 65 host := getDockerHostFromEnv(testEnv) 66 assert.Equal(t, test.Expected, host) 67 }) 68 } 69 70 t.Run("GetDockerHostFromEnv: DOCKER_HOST unset", func(t *testing.T) { 71 t.Parallel() 72 73 testEnv := []string{ 74 "FOO=bar", 75 "BAR=baz", 76 } 77 78 host := getDockerHostFromEnv(testEnv) 79 assert.Equal(t, "localhost", host) 80 }) 81 }