diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 4a7e363d1c..f60436766a 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1372,8 +1372,7 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) { Image: "busybox", } - var httpClient *http.Client - cli, err := client.NewClient(daemonHost(), "v1.18", httpClient, map[string]string{}) + cli, err := NewEnvClientWithVersion("v1.18") _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, "") c.Assert(err, checker.IsNil) diff --git a/integration-cli/docker_api_images_test.go b/integration-cli/docker_api_images_test.go index 8ad12fb77d..4b3fb059cf 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -179,8 +179,7 @@ func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) { Labels map[string]string } - var httpClient *http.Client - cli, err = client.NewClient(daemonHost(), "v1.24", httpClient, nil) + cli, err = NewEnvClientWithVersion("v1.24") c.Assert(err, checker.IsNil) defer cli.Close() diff --git a/integration-cli/docker_api_inspect_unix_test.go b/integration-cli/docker_api_inspect_unix_test.go index 93c40947af..7fc4cb0b45 100644 --- a/integration-cli/docker_api_inspect_unix_test.go +++ b/integration-cli/docker_api_inspect_unix_test.go @@ -4,9 +4,7 @@ package main import ( "encoding/json" - "net/http" - "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" "golang.org/x/net/context" @@ -19,8 +17,7 @@ func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) { name := "cpusetinconfig-pre120" dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true") - var httpClient *http.Client - cli, err := client.NewClient(daemonHost(), "v1.19", httpClient, nil) + cli, err := NewEnvClientWithVersion("v1.19") c.Assert(err, checker.IsNil) defer cli.Close() _, body, err := cli.ContainerInspectWithRaw(context.Background(), name, false) diff --git a/integration-cli/docker_cli_kill_test.go b/integration-cli/docker_cli_kill_test.go index ea1c269812..a949bdb37f 100644 --- a/integration-cli/docker_cli_kill_test.go +++ b/integration-cli/docker_cli_kill_test.go @@ -1,11 +1,9 @@ package main import ( - "net/http" "strings" "time" - "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/checker" "github.com/docker/docker/integration-cli/cli" "github.com/go-check/check" @@ -131,8 +129,7 @@ func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) { testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later runSleepingContainer(c, "--name", "docker-kill-test-api", "-d") dockerCmd(c, "stop", "docker-kill-test-api") - var httpClient *http.Client - cli, err := client.NewClient(daemonHost(), "v1.19", httpClient, nil) + cli, err := NewEnvClientWithVersion("v1.19") c.Assert(err, check.IsNil) defer cli.Close() err = cli.ContainerKill(context.Background(), "docker-kill-test-api", "SIGKILL") diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 485d718f17..45a56bcfed 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -4127,7 +4127,7 @@ func (s *DockerSuite) TestRunRm(c *check.C) { // Test that auto-remove is performed by the client on API versions that do not support daemon-side api-remove (API < 1.25) func (s *DockerSuite) TestRunRmPre125Api(c *check.C) { name := "miss-me-when-im-gone" - envs := appendBaseEnv(false, "DOCKER_API_VERSION=1.24") + envs := appendBaseEnv(os.Getenv("DOCKER_TLS_VERIFY") != "", "DOCKER_API_VERSION=1.24") cli.Docker(cli.Args("run", "--name="+name, "--rm", "busybox"), cli.WithEnvironmentVariables(envs...)).Assert(c, icmd.Success) cli.Docker(cli.Inspect(name), cli.Format(".name")).Assert(c, icmd.Expected{ diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index 95d2e93cfe..194e0660f2 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/ioutil" - "net/http" "os" "path" "path/filepath" @@ -373,8 +372,7 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg } func getInspectBody(c *check.C, version, id string) []byte { - var httpClient *http.Client - cli, err := client.NewClient(daemonHost(), version, httpClient, nil) + cli, err := NewEnvClientWithVersion(version) c.Assert(err, check.IsNil) defer cli.Close() _, body, err := cli.ContainerInspectWithRaw(context.Background(), id, false) diff --git a/integration-cli/request/request.go b/integration-cli/request/request.go index 72632f3f76..f2b0320bd0 100644 --- a/integration-cli/request/request.go +++ b/integration-cli/request/request.go @@ -129,7 +129,11 @@ func New(host, endpoint string, modifiers ...func(*http.Request) error) (*http.R return nil, fmt.Errorf("could not create new request: %v", err) } - req.URL.Scheme = "http" + if os.Getenv("DOCKER_TLS_VERIFY") != "" { + req.URL.Scheme = "https" + } else { + req.URL.Scheme = "http" + } req.URL.Host = addr for _, config := range modifiers { diff --git a/integration-cli/utils_test.go b/integration-cli/utils_test.go index 26b0b3106c..5a7e566d87 100644 --- a/integration-cli/utils_test.go +++ b/integration-cli/utils_test.go @@ -183,3 +183,14 @@ func RemoveOutputForExistingElements(output string, existing []string) string { res := RemoveLinesForExistingElements(strings.Split(output, "\n"), existing) return strings.Join(res, "\n") } + +// NewEnvClientWithVersion returns a docker client with a specified version. +// See: github.com/docker/docker/client `NewEnvClient()` +func NewEnvClientWithVersion(version string) (*client.Client, error) { + cli, err := client.NewEnvClient() + if err != nil { + return nil, err + } + cli.NegotiateAPIVersionPing(types.Ping{APIVersion: version}) + return cli, nil +}