-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathdocker.go
More file actions
43 lines (35 loc) · 1.09 KB
/
docker.go
File metadata and controls
43 lines (35 loc) · 1.09 KB
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
33
34
35
36
37
38
39
40
41
42
43
// Copyright IBM Corp. 2015, 2025
// SPDX-License-Identifier: BUSL-1.1
package testutil
import (
"runtime"
"testing"
"github.com/hashicorp/nomad/testutil"
docker "github.com/moby/moby/client"
)
// 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() {
// Travis supports Docker on Linux only; MacOS setup does not support Docker
return runtime.GOOS == "linux"
}
if testutil.IsAppVeyor() {
return runtime.GOOS == "windows"
}
client, err := docker.NewClientWithOpts(docker.FromEnv, docker.WithAPIVersionNegotiation())
if err != nil {
return false
}
// Creating a client doesn't actually connect, so make sure we do something
// like call ClientVersion() on it.
ver := client.ClientVersion()
t.Logf("Successfully connected to docker daemon running version %s", ver)
return true
}
// DockerCompatible skips tests if docker is not present
func DockerCompatible(t *testing.T) {
if !DockerIsConnected(t) {
t.Skip("Docker not connected")
}
}