forked from hashicorp/nomad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.go
32 lines (26 loc) · 765 Bytes
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package testutil
import (
"testing"
docker "github.com/fsouza/go-dockerclient"
"github.com/hashicorp/nomad/testutil"
)
// DockerIsConnected checks to see if a docker daemon is available (local or remote)
func DockerIsConnected(t *testing.T) bool {
// We have docker on travis so we should try to test
if testutil.IsTravis() {
return true
}
client, err := docker.NewClientFromEnv()
if err != nil {
return false
}
// Creating a client doesn't actually connect, so make sure we do something
// like call Version() on it.
env, err := client.Version()
if err != nil {
t.Logf("Failed to connect to docker daemon: %s", err)
return false
}
t.Logf("Successfully connected to docker daemon running version %s", env.Get("Version"))
return true
}