소스 검색

Migrate some calls to new client function

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Vincent Demeester 7 년 전
부모
커밋
6977f468bb

+ 1 - 1
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)

+ 2 - 1
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)

+ 1 - 1
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()
 

+ 2 - 2
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)

+ 1 - 1
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)

+ 1 - 43
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
-}

+ 0 - 5
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,

+ 1 - 2
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"

+ 2 - 2
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()

+ 4 - 5
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()

+ 1 - 2
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()

+ 2 - 2
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()
 

+ 1 - 1
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")
 	}