Files
nomad/client/testutil/docker.go
Piotr Kazmierczak 981ca36049 docker: use official client instead of fsouza/go-dockerclient (#23966)
This PR replaces fsouza/go-dockerclient 3rd party docker client library with
docker's official SDK.

---------

Co-authored-by: Tim Gross <tgross@hashicorp.com>
Co-authored-by: Seth Hoenig <shoenig@duck.com>
2024-09-26 18:41:44 +02:00

44 lines
1.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package testutil
import (
"runtime"
"testing"
docker "github.com/docker/docker/client"
"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() {
// 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")
}
}