From 6977f468bbcf43864a5acf6c89c331a9180169e5 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Wed, 31 Jan 2018 15:01:29 -0800 Subject: [PATCH] Migrate some calls to new client function Signed-off-by: Vincent Demeester --- integration-cli/daemon/daemon.go | 2 +- integration-cli/docker_api_containers_test.go | 3 +- integration-cli/docker_api_images_test.go | 2 +- .../docker_api_inspect_unix_test.go | 4 +- integration-cli/docker_utils_test.go | 2 +- integration-cli/request/request.go | 44 +------------------ integration/container/kill_test.go | 5 --- integration/network/inspect_test.go | 3 +- integration/secret/secret_test.go | 4 +- integration/service/create_test.go | 9 ++-- integration/service/inspect_test.go | 3 +- integration/service/network_test.go | 4 +- internal/test/environment/environment.go | 2 +- 13 files changed, 19 insertions(+), 68 deletions(-) diff --git a/integration-cli/daemon/daemon.go b/integration-cli/daemon/daemon.go index 149d775fea..69a87d9d9c 100644 --- a/integration-cli/daemon/daemon.go +++ b/integration-cli/daemon/daemon.go @@ -566,7 +566,7 @@ func (d *Daemon) WaitRun(contID string) error { // Info returns the info struct for this daemon func (d *Daemon) Info(t require.TestingT) types.Info { - apiclient, err := request.NewClientForHost(d.Sock()) + apiclient, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) info, err := apiclient.Info(context.Background()) require.NoError(t, err) diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 02e8e9f7d2..a91c91abe5 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1372,7 +1372,8 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) { Image: "busybox", } - cli, err := request.NewEnvClientWithVersion("v1.18") + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("v1.18")) + c.Assert(err, checker.IsNil) _, 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 10cb52eeb0..a5628e41b9 100644 --- a/integration-cli/docker_api_images_test.go +++ b/integration-cli/docker_api_images_test.go @@ -179,7 +179,7 @@ func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) { Labels map[string]string } - cli, err = request.NewEnvClientWithVersion("v1.24") + cli, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("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 dae64be2a7..17844e0bfc 100644 --- a/integration-cli/docker_api_inspect_unix_test.go +++ b/integration-cli/docker_api_inspect_unix_test.go @@ -5,8 +5,8 @@ package main import ( "encoding/json" + "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/checker" - "github.com/docker/docker/integration-cli/request" "github.com/go-check/check" "golang.org/x/net/context" ) @@ -18,7 +18,7 @@ func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) { name := "cpusetinconfig-pre120" dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true") - cli, err := request.NewEnvClientWithVersion("v1.19") + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("v1.19")) c.Assert(err, checker.IsNil) defer cli.Close() _, body, err := cli.ContainerInspectWithRaw(context.Background(), name, false) diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index 6eda88c684..ea780cc6e8 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -372,7 +372,7 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg } func getInspectBody(c *check.C, version, id string) []byte { - cli, err := request.NewEnvClientWithVersion(version) + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(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 a937708665..e4a1e3e892 100644 --- a/integration-cli/request/request.go +++ b/integration-cli/request/request.go @@ -17,7 +17,6 @@ import ( "strings" "time" - "github.com/docker/docker/api" dclient "github.com/docker/docker/client" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/ioutils" @@ -169,16 +168,7 @@ func NewHTTPClient(host string) (*http.Client, error) { // NewClient returns a new Docker API client func NewClient() (dclient.APIClient, error) { - return NewClientForHost(DaemonHost()) -} - -// NewClientForHost returns a Docker API client for the host -func NewClientForHost(host string) (dclient.APIClient, error) { - httpClient, err := NewHTTPClient(host) - if err != nil { - return nil, err - } - return dclient.NewClient(host, api.DefaultVersion, httpClient, nil) + return dclient.NewClientWithOpts(dclient.WithHost(DaemonHost())) } // FIXME(vdemeester) httputil.ClientConn is deprecated, use http.Client instead (closer to actual client) @@ -323,35 +313,3 @@ func DaemonHost() string { } return daemonURLStr } - -// NewEnvClientWithVersion returns a docker client with a specified version. -// See: github.com/docker/docker/client `NewEnvClient()` -func NewEnvClientWithVersion(version string) (*dclient.Client, error) { - if version == "" { - return nil, errors.New("version not specified") - } - - var httpClient *http.Client - if os.Getenv("DOCKER_CERT_PATH") != "" { - tlsConfig, err := getTLSConfig() - if err != nil { - return nil, err - } - httpClient = &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: tlsConfig, - }, - } - } - - host := os.Getenv("DOCKER_HOST") - if host == "" { - host = dclient.DefaultDockerHost - } - - cli, err := dclient.NewClient(host, version, httpClient, nil) - if err != nil { - return cli, err - } - return cli, nil -} diff --git a/integration/container/kill_test.go b/integration/container/kill_test.go index 238515566d..57343942da 100644 --- a/integration/container/kill_test.go +++ b/integration/container/kill_test.go @@ -19,7 +19,6 @@ import ( func TestKillContainerInvalidSignal(t *testing.T) { defer setupTest(t)() client := request.NewAPIClient(t) - t.Parallel() ctx := context.Background() c, err := client.ContainerCreate(ctx, &container.Config{ @@ -71,7 +70,6 @@ func TestKillContainer(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.doc, func(t *testing.T) { - t.Parallel() ctx := context.Background() c, err := client.ContainerCreate(ctx, &container.Config{ @@ -117,7 +115,6 @@ func TestKillWithStopSignalAndRestartPolicies(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.doc, func(t *testing.T) { - t.Parallel() ctx := context.Background() c, err := client.ContainerCreate(ctx, &container.Config{ @@ -145,7 +142,6 @@ func TestKillWithStopSignalAndRestartPolicies(t *testing.T) { func TestKillStoppedContainer(t *testing.T) { skip.If(t, testEnv.OSType != "linux") // Windows only supports 1.25 or later defer setupTest(t)() - t.Parallel() ctx := context.Background() client := request.NewAPIClient(t) c, err := client.ContainerCreate(ctx, @@ -165,7 +161,6 @@ func TestKillStoppedContainer(t *testing.T) { func TestKillStoppedContainerAPIPre120(t *testing.T) { skip.If(t, testEnv.OSType != "linux") // Windows only supports 1.25 or later defer setupTest(t)() - t.Parallel() ctx := context.Background() client := request.NewAPIClient(t, client.WithVersion("1.19")) c, err := client.ContainerCreate(ctx, diff --git a/integration/network/inspect_test.go b/integration/network/inspect_test.go index 36b65d1d11..94218af084 100644 --- a/integration/network/inspect_test.go +++ b/integration/network/inspect_test.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/daemon" - "github.com/docker/docker/integration-cli/request" "github.com/gotestyourself/gotestyourself/poll" "github.com/stretchr/testify/require" "golang.org/x/net/context" @@ -24,7 +23,7 @@ func TestInspectNetwork(t *testing.T) { defer setupTest(t)() d := newSwarm(t) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) overlayName := "overlay1" diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 7637304ad8..922fd33028 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -4,7 +4,7 @@ import ( "testing" swarmtypes "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/integration-cli/request" + "github.com/docker/docker/client" "github.com/docker/docker/integration/util/swarm" "github.com/gotestyourself/gotestyourself/skip" "github.com/stretchr/testify/assert" @@ -18,7 +18,7 @@ func TestSecretInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) ctx := context.Background() diff --git a/integration/service/create_test.go b/integration/service/create_test.go index 19b9eee949..c74c8fb52e 100644 --- a/integration/service/create_test.go +++ b/integration/service/create_test.go @@ -10,7 +10,6 @@ import ( "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/integration/util/swarm" "github.com/gotestyourself/gotestyourself/poll" "github.com/stretchr/testify/assert" @@ -22,7 +21,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) overlayName := "overlay1" @@ -88,7 +87,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) name := "foo" @@ -150,7 +149,7 @@ func TestCreateServiceSecretFileMode(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) ctx := context.Background() @@ -231,7 +230,7 @@ func TestCreateServiceConfigFileMode(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) ctx := context.Background() diff --git a/integration/service/inspect_test.go b/integration/service/inspect_test.go index 2ca0ec6b06..8fe97d98ad 100644 --- a/integration/service/inspect_test.go +++ b/integration/service/inspect_test.go @@ -9,7 +9,6 @@ import ( "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/integration/util/swarm" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" @@ -23,7 +22,7 @@ func TestInspect(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) var before = time.Now() diff --git a/integration/service/network_test.go b/integration/service/network_test.go index 089c7ae19c..1a9297c6b3 100644 --- a/integration/service/network_test.go +++ b/integration/service/network_test.go @@ -7,7 +7,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" - "github.com/docker/docker/integration-cli/request" + "github.com/docker/docker/client" "github.com/docker/docker/integration/util/swarm" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -17,7 +17,7 @@ func TestDockerNetworkConnectAlias(t *testing.T) { defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) - client, err := request.NewClientForHost(d.Sock()) + client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) require.NoError(t, err) ctx := context.Background() diff --git a/internal/test/environment/environment.go b/internal/test/environment/environment.go index 5ff4139e5d..bde4c0a1bc 100644 --- a/internal/test/environment/environment.go +++ b/internal/test/environment/environment.go @@ -32,7 +32,7 @@ type PlatformDefaults struct { // New creates a new Execution struct func New() (*Execution, error) { - client, err := client.NewEnvClient() + client, err := client.NewClientWithOpts(client.FromEnv) if err != nil { return nil, errors.Wrapf(err, "failed to create client") }