github.com/bigcommerce/nomad@v0.9.3-bc/client/testutil/docker.go (about) 1 package testutil 2 3 import ( 4 "runtime" 5 "testing" 6 7 docker "github.com/fsouza/go-dockerclient" 8 "github.com/hashicorp/nomad/testutil" 9 ) 10 11 // DockerIsConnected checks to see if a docker daemon is available (local or remote) 12 func DockerIsConnected(t *testing.T) bool { 13 // We have docker on travis so we should try to test 14 if testutil.IsTravis() { 15 // Travis supports Docker on Linux only; MacOS setup does not support Docker 16 return runtime.GOOS == "linux" 17 } 18 19 if testutil.IsAppVeyor() { 20 return runtime.GOOS == "windows" 21 } 22 23 client, err := docker.NewClientFromEnv() 24 if err != nil { 25 return false 26 } 27 28 // Creating a client doesn't actually connect, so make sure we do something 29 // like call Version() on it. 30 env, err := client.Version() 31 if err != nil { 32 t.Logf("Failed to connect to docker daemon: %s", err) 33 return false 34 } 35 36 t.Logf("Successfully connected to docker daemon running version %s", env.Get("Version")) 37 return true 38 } 39 40 // DockerCompatible skips tests if docker is not present 41 func DockerCompatible(t *testing.T) { 42 if !DockerIsConnected(t) { 43 t.Skip("Docker not connected") 44 } 45 }