Migrate some calls to new client function
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
2227c8ad5e
commit
6977f468bb
|
@ -566,7 +566,7 @@ func (d *Daemon) WaitRun(contID string) error {
|
||||||
|
|
||||||
// Info returns the info struct for this daemon
|
// Info returns the info struct for this daemon
|
||||||
func (d *Daemon) Info(t require.TestingT) types.Info {
|
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)
|
require.NoError(t, err)
|
||||||
info, err := apiclient.Info(context.Background())
|
info, err := apiclient.Info(context.Background())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -1372,7 +1372,8 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) {
|
||||||
Image: "busybox",
|
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{}, "")
|
_, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, "")
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
|
@ -179,7 +179,7 @@ func (s *DockerSuite) TestAPIImagesSizeCompatibility(c *check.C) {
|
||||||
Labels map[string]string
|
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)
|
c.Assert(err, checker.IsNil)
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration-cli/checker"
|
"github.com/docker/docker/integration-cli/checker"
|
||||||
"github.com/docker/docker/integration-cli/request"
|
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,7 @@ func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) {
|
||||||
|
|
||||||
name := "cpusetinconfig-pre120"
|
name := "cpusetinconfig-pre120"
|
||||||
dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true")
|
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)
|
c.Assert(err, checker.IsNil)
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
_, body, err := cli.ContainerInspectWithRaw(context.Background(), name, false)
|
_, body, err := cli.ContainerInspectWithRaw(context.Background(), name, false)
|
||||||
|
|
|
@ -372,7 +372,7 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInspectBody(c *check.C, version, id string) []byte {
|
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)
|
c.Assert(err, check.IsNil)
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
_, body, err := cli.ContainerInspectWithRaw(context.Background(), id, false)
|
_, body, err := cli.ContainerInspectWithRaw(context.Background(), id, false)
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api"
|
|
||||||
dclient "github.com/docker/docker/client"
|
dclient "github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
|
@ -169,16 +168,7 @@ func NewHTTPClient(host string) (*http.Client, error) {
|
||||||
|
|
||||||
// NewClient returns a new Docker API client
|
// NewClient returns a new Docker API client
|
||||||
func NewClient() (dclient.APIClient, error) {
|
func NewClient() (dclient.APIClient, error) {
|
||||||
return NewClientForHost(DaemonHost())
|
return dclient.NewClientWithOpts(dclient.WithHost(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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(vdemeester) httputil.ClientConn is deprecated, use http.Client instead (closer to actual client)
|
// FIXME(vdemeester) httputil.ClientConn is deprecated, use http.Client instead (closer to actual client)
|
||||||
|
@ -323,35 +313,3 @@ func DaemonHost() string {
|
||||||
}
|
}
|
||||||
return daemonURLStr
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
func TestKillContainerInvalidSignal(t *testing.T) {
|
func TestKillContainerInvalidSignal(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
client := request.NewAPIClient(t)
|
client := request.NewAPIClient(t)
|
||||||
t.Parallel()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := client.ContainerCreate(ctx,
|
c, err := client.ContainerCreate(ctx,
|
||||||
&container.Config{
|
&container.Config{
|
||||||
|
@ -71,7 +70,6 @@ func TestKillContainer(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.doc, func(t *testing.T) {
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := client.ContainerCreate(ctx,
|
c, err := client.ContainerCreate(ctx,
|
||||||
&container.Config{
|
&container.Config{
|
||||||
|
@ -117,7 +115,6 @@ func TestKillWithStopSignalAndRestartPolicies(t *testing.T) {
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.doc, func(t *testing.T) {
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c, err := client.ContainerCreate(ctx,
|
c, err := client.ContainerCreate(ctx,
|
||||||
&container.Config{
|
&container.Config{
|
||||||
|
@ -145,7 +142,6 @@ func TestKillWithStopSignalAndRestartPolicies(t *testing.T) {
|
||||||
func TestKillStoppedContainer(t *testing.T) {
|
func TestKillStoppedContainer(t *testing.T) {
|
||||||
skip.If(t, testEnv.OSType != "linux") // Windows only supports 1.25 or later
|
skip.If(t, testEnv.OSType != "linux") // Windows only supports 1.25 or later
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
t.Parallel()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := request.NewAPIClient(t)
|
client := request.NewAPIClient(t)
|
||||||
c, err := client.ContainerCreate(ctx,
|
c, err := client.ContainerCreate(ctx,
|
||||||
|
@ -165,7 +161,6 @@ func TestKillStoppedContainer(t *testing.T) {
|
||||||
func TestKillStoppedContainerAPIPre120(t *testing.T) {
|
func TestKillStoppedContainerAPIPre120(t *testing.T) {
|
||||||
skip.If(t, testEnv.OSType != "linux") // Windows only supports 1.25 or later
|
skip.If(t, testEnv.OSType != "linux") // Windows only supports 1.25 or later
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
t.Parallel()
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client := request.NewAPIClient(t, client.WithVersion("1.19"))
|
client := request.NewAPIClient(t, client.WithVersion("1.19"))
|
||||||
c, err := client.ContainerCreate(ctx,
|
c, err := client.ContainerCreate(ctx,
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration-cli/daemon"
|
"github.com/docker/docker/integration-cli/daemon"
|
||||||
"github.com/docker/docker/integration-cli/request"
|
|
||||||
"github.com/gotestyourself/gotestyourself/poll"
|
"github.com/gotestyourself/gotestyourself/poll"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -24,7 +23,7 @@ func TestInspectNetwork(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := newSwarm(t)
|
d := newSwarm(t)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
overlayName := "overlay1"
|
overlayName := "overlay1"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
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/docker/docker/integration/util/swarm"
|
||||||
"github.com/gotestyourself/gotestyourself/skip"
|
"github.com/gotestyourself/gotestyourself/skip"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -18,7 +18,7 @@ func TestSecretInspect(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration-cli/request"
|
|
||||||
"github.com/docker/docker/integration/util/swarm"
|
"github.com/docker/docker/integration/util/swarm"
|
||||||
"github.com/gotestyourself/gotestyourself/poll"
|
"github.com/gotestyourself/gotestyourself/poll"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -22,7 +21,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
overlayName := "overlay1"
|
overlayName := "overlay1"
|
||||||
|
@ -88,7 +87,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
name := "foo"
|
name := "foo"
|
||||||
|
@ -150,7 +149,7 @@ func TestCreateServiceSecretFileMode(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -231,7 +230,7 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
swarmtypes "github.com/docker/docker/api/types/swarm"
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration-cli/request"
|
|
||||||
"github.com/docker/docker/integration/util/swarm"
|
"github.com/docker/docker/integration/util/swarm"
|
||||||
"github.com/gotestyourself/gotestyourself/poll"
|
"github.com/gotestyourself/gotestyourself/poll"
|
||||||
"github.com/gotestyourself/gotestyourself/skip"
|
"github.com/gotestyourself/gotestyourself/skip"
|
||||||
|
@ -23,7 +22,7 @@ func TestInspect(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
var before = time.Now()
|
var before = time.Now()
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/network"
|
"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/docker/docker/integration/util/swarm"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -17,7 +17,7 @@ func TestDockerNetworkConnectAlias(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
d := swarm.NewSwarm(t, testEnv)
|
d := swarm.NewSwarm(t, testEnv)
|
||||||
defer d.Stop(t)
|
defer d.Stop(t)
|
||||||
client, err := request.NewClientForHost(d.Sock())
|
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ type PlatformDefaults struct {
|
||||||
|
|
||||||
// New creates a new Execution struct
|
// New creates a new Execution struct
|
||||||
func New() (*Execution, error) {
|
func New() (*Execution, error) {
|
||||||
client, err := client.NewEnvClient()
|
client, err := client.NewClientWithOpts(client.FromEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create client")
|
return nil, errors.Wrapf(err, "failed to create client")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue