1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Test: Replace NewClient() with NewClientT()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2018-12-22 15:53:02 +01:00
parent 2cb26cfe9c
commit 2cb7b73a1b
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
19 changed files with 200 additions and 241 deletions

View file

@ -67,8 +67,7 @@ func (d *Daemon) CheckServiceUpdateState(service string) func(*check.C) (interfa
// CheckPluginRunning returns the runtime state of the plugin // CheckPluginRunning returns the runtime state of the plugin
func (d *Daemon) CheckPluginRunning(plugin string) func(c *check.C) (interface{}, check.CommentInterface) { func (d *Daemon) CheckPluginRunning(plugin string) func(c *check.C) (interface{}, check.CommentInterface) {
return func(c *check.C) (interface{}, check.CommentInterface) { return func(c *check.C) (interface{}, check.CommentInterface) {
apiclient, err := d.NewClient() apiclient := d.NewClientT(c)
assert.NilError(c, err)
resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin) resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin)
if client.IsErrNotFound(err) { if client.IsErrNotFound(err) {
return false, check.Commentf("%v", err) return false, check.Commentf("%v", err)
@ -81,8 +80,7 @@ func (d *Daemon) CheckPluginRunning(plugin string) func(c *check.C) (interface{}
// CheckPluginImage returns the runtime state of the plugin // CheckPluginImage returns the runtime state of the plugin
func (d *Daemon) CheckPluginImage(plugin string) func(c *check.C) (interface{}, check.CommentInterface) { func (d *Daemon) CheckPluginImage(plugin string) func(c *check.C) (interface{}, check.CommentInterface) {
return func(c *check.C) (interface{}, check.CommentInterface) { return func(c *check.C) (interface{}, check.CommentInterface) {
apiclient, err := d.NewClient() apiclient := d.NewClientT(c)
assert.NilError(c, err)
resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin) resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin)
if client.IsErrNotFound(err) { if client.IsErrNotFound(err) {
return false, check.Commentf("%v", err) return false, check.Commentf("%v", err)
@ -102,8 +100,7 @@ func (d *Daemon) CheckServiceTasks(service string) func(*check.C) (interface{},
// CheckRunningTaskNetworks returns the number of times each network is referenced from a task. // CheckRunningTaskNetworks returns the number of times each network is referenced from a task.
func (d *Daemon) CheckRunningTaskNetworks(c *check.C) (interface{}, check.CommentInterface) { func (d *Daemon) CheckRunningTaskNetworks(c *check.C) (interface{}, check.CommentInterface) {
cli, err := d.NewClient() cli := d.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
filterArgs := filters.NewArgs() filterArgs := filters.NewArgs()
@ -127,8 +124,7 @@ func (d *Daemon) CheckRunningTaskNetworks(c *check.C) (interface{}, check.Commen
// CheckRunningTaskImages returns the times each image is running as a task. // CheckRunningTaskImages returns the times each image is running as a task.
func (d *Daemon) CheckRunningTaskImages(c *check.C) (interface{}, check.CommentInterface) { func (d *Daemon) CheckRunningTaskImages(c *check.C) (interface{}, check.CommentInterface) {
cli, err := d.NewClient() cli := d.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
filterArgs := filters.NewArgs() filterArgs := filters.NewArgs()
@ -177,8 +173,7 @@ func (d *Daemon) CheckControlAvailable(c *check.C) (interface{}, check.CommentIn
// CheckLeader returns whether there is a leader on the swarm or not // CheckLeader returns whether there is a leader on the swarm or not
func (d *Daemon) CheckLeader(c *check.C) (interface{}, check.CommentInterface) { func (d *Daemon) CheckLeader(c *check.C) (interface{}, check.CommentInterface) {
cli, err := d.NewClient() cli := d.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
errList := check.Commentf("could not get node list") errList := check.Commentf("could not get node list")

View file

@ -66,20 +66,19 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesCreate(c *check.C) {
id := d.CreateService(c, simpleTestService, setInstances(instances)) id := d.CreateService(c, simpleTestService, setInstances(instances))
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
cli, err := d.NewClient() client := d.NewClientT(c)
c.Assert(err, checker.IsNil) defer client.Close()
defer cli.Close()
options := types.ServiceInspectOptions{InsertDefaults: true} options := types.ServiceInspectOptions{InsertDefaults: true}
// insertDefaults inserts UpdateConfig when service is fetched by ID // insertDefaults inserts UpdateConfig when service is fetched by ID
resp, _, err := cli.ServiceInspectWithRaw(context.Background(), id, options) resp, _, err := client.ServiceInspectWithRaw(context.Background(), id, options)
out := fmt.Sprintf("%+v", resp) out := fmt.Sprintf("%+v", resp)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "UpdateConfig") c.Assert(out, checker.Contains, "UpdateConfig")
// insertDefaults inserts UpdateConfig when service is fetched by ID // insertDefaults inserts UpdateConfig when service is fetched by ID
resp, _, err = cli.ServiceInspectWithRaw(context.Background(), "top", options) resp, _, err = client.ServiceInspectWithRaw(context.Background(), "top", options)
out = fmt.Sprintf("%+v", resp) out = fmt.Sprintf("%+v", resp)
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(string(out), checker.Contains, "UpdateConfig") c.Assert(string(out), checker.Contains, "UpdateConfig")

View file

@ -377,13 +377,12 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *check.C) {
var service swarm.Service var service swarm.Service
simpleTestService(&service) simpleTestService(&service)
service.Spec.Name = "top2" service.Spec.Name = "top2"
cli, err := d1.NewClient() cli := d1.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
// d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen // d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen
waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) { waitAndAssert(c, defaultReconciliationTimeout, func(c *check.C) (interface{}, check.CommentInterface) {
_, err = cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{}) _, err := cli.ServiceCreate(context.Background(), service.Spec, types.ServiceCreateOptions{})
return err.Error(), nil return err.Error(), nil
}, checker.Contains, "Make sure more than half of the managers are online.") }, checker.Contains, "Make sure more than half of the managers are online.")
@ -849,10 +848,9 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateWithName(c *check.C) {
instances = 5 instances = 5
setInstances(instances)(service) setInstances(instances)(service)
cli, err := d.NewClient() cli := d.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
_, err = cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{}) _, err := cli.ServiceUpdate(context.Background(), service.Spec.Name, service.Version, service.Spec, types.ServiceUpdateOptions{})
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances) waitAndAssert(c, defaultReconciliationTimeout, d.CheckActiveContainerCount, checker.Equals, instances)
} }
@ -884,8 +882,7 @@ func (s *DockerSwarmSuite) TestAPISwarmErrorHandling(c *check.C) {
// This test makes sure the fixes correctly output scopes instead. // This test makes sure the fixes correctly output scopes instead.
func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) { func (s *DockerSwarmSuite) TestAPIDuplicateNetworks(c *check.C) {
d := s.AddDaemon(c, true, true) d := s.AddDaemon(c, true, true)
cli, err := d.NewClient() cli := d.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
name := "foo" name := "foo"
@ -1014,8 +1011,7 @@ func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *check.C) {
name := "test-scoped-network" name := "test-scoped-network"
ctx := context.Background() ctx := context.Background()
apiclient, err := d.NewClient() apiclient := d.NewClientT(c)
assert.NilError(c, err)
resp, err := apiclient.NetworkCreate(ctx, name, types.NetworkCreate{Driver: "overlay"}) resp, err := apiclient.NetworkCreate(ctx, name, types.NetworkCreate{Driver: "overlay"})
assert.NilError(c, err) assert.NilError(c, err)

View file

@ -425,8 +425,7 @@ func (s *DockerSwarmSuite) TestOverlayAttachableOnSwarmLeave(c *check.C) {
c.Assert(err, checker.IsNil, check.Commentf("%s", out)) c.Assert(err, checker.IsNil, check.Commentf("%s", out))
// Leave the swarm // Leave the swarm
err = d.SwarmLeave(true) c.Assert(d.SwarmLeave(true), checker.IsNil)
c.Assert(err, checker.IsNil)
// Check the container is disconnected // Check the container is disconnected
out, err = d.Cmd("inspect", "c1", "--format", "{{.NetworkSettings.Networks."+nwName+"}}") out, err = d.Cmd("inspect", "c1", "--format", "{{.NetworkSettings.Networks."+nwName+"}}")
@ -1612,8 +1611,7 @@ func (s *DockerSwarmSuite) TestNetworkInspectWithDuplicateNames(c *check.C) {
Driver: "bridge", Driver: "bridge",
} }
cli, err := d.NewClient() cli := d.NewClientT(c)
c.Assert(err, checker.IsNil)
defer cli.Close() defer cli.Close()
n1, err := cli.NetworkCreate(context.Background(), name, options) n1, err := cli.NetworkCreate(context.Background(), name, options)

View file

@ -36,18 +36,17 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
d.StartWithBusybox(t, "--iptables=false") d.StartWithBusybox(t, "--iptables=false")
defer d.Stop(t) defer d.Stop(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.Check(t, err, "error creating client")
ctx := context.Background() ctx := context.Background()
cID := container.Create(t, ctx, client) cID := container.Create(t, ctx, c)
defer client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{}) err := c.ContainerStart(ctx, cID, types.ContainerStartOptions{})
assert.Check(t, err, "error starting test container") assert.Check(t, err, "error starting test container")
inspect, err := client.ContainerInspect(ctx, cID) inspect, err := c.ContainerInspect(ctx, cID)
assert.Check(t, err, "error getting inspect data") assert.Check(t, err, "error getting inspect data")
ppid := getContainerdShimPid(t, inspect) ppid := getContainerdShimPid(t, inspect)
@ -63,7 +62,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
d.Start(t, "--iptables=false") d.Start(t, "--iptables=false")
err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{}) err = c.ContainerStart(ctx, cID, types.ContainerStartOptions{})
assert.Check(t, err, "failed to start test container") assert.Check(t, err, "failed to start test container")
} }

View file

@ -62,17 +62,16 @@ func TestExportContainerAfterDaemonRestart(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
d := daemon.New(t) d := daemon.New(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
d.StartWithBusybox(t) d.StartWithBusybox(t)
defer d.Stop(t) defer d.Stop(t)
ctx := context.Background() ctx := context.Background()
ctrID := container.Create(t, ctx, client) ctrID := container.Create(t, ctx, c)
d.Restart(t) d.Restart(t)
_, err = client.ContainerExport(ctx, ctrID) _, err := c.ContainerExport(ctx, ctrID)
assert.NilError(t, err) assert.NilError(t, err)
} }

View file

@ -228,8 +228,7 @@ func testDaemonIpcPrivateShareable(t *testing.T, mustBeShared bool, arg ...strin
d.StartWithBusybox(t, arg...) d.StartWithBusybox(t, arg...)
defer d.Stop(t) defer d.Stop(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.Check(t, err, "error creating client")
cfg := containertypes.Config{ cfg := containertypes.Config{
Image: "busybox", Image: "busybox",
@ -237,16 +236,16 @@ func testDaemonIpcPrivateShareable(t *testing.T, mustBeShared bool, arg ...strin
} }
ctx := context.Background() ctx := context.Background()
resp, err := client.ContainerCreate(ctx, &cfg, &containertypes.HostConfig{}, nil, "") resp, err := c.ContainerCreate(ctx, &cfg, &containertypes.HostConfig{}, nil, "")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(len(resp.Warnings), 0)) assert.Check(t, is.Equal(len(resp.Warnings), 0))
err = client.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) err = c.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
assert.NilError(t, err) assert.NilError(t, err)
// get major:minor pair for /dev/shm from container's /proc/self/mountinfo // get major:minor pair for /dev/shm from container's /proc/self/mountinfo
cmd := "awk '($5 == \"/dev/shm\") {printf $3}' /proc/self/mountinfo" cmd := "awk '($5 == \"/dev/shm\") {printf $3}' /proc/self/mountinfo"
result, err := container.Exec(ctx, client, resp.ID, []string{"sh", "-c", cmd}) result, err := container.Exec(ctx, c, resp.ID, []string{"sh", "-c", cmd})
assert.NilError(t, err) assert.NilError(t, err)
mm := result.Combined() mm := result.Combined()
assert.Check(t, is.Equal(true, regexp.MustCompile("^[0-9]+:[0-9]+$").MatchString(mm))) assert.Check(t, is.Equal(true, regexp.MustCompile("^[0-9]+:[0-9]+$").MatchString(mm)))

View file

@ -26,7 +26,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
xStart bool xStart bool
} }
for _, c := range []testCase{ for _, tc := range []testCase{
{ {
desc: "container without restart policy", desc: "container without restart policy",
config: &container.Config{Image: "busybox", Cmd: []string{"top"}}, config: &container.Config{Image: "busybox", Cmd: []string{"top"}},
@ -57,16 +57,15 @@ func TestDaemonRestartKillContainers(t *testing.T) {
d.Stop(t) d.Stop(t)
}, },
} { } {
t.Run(fmt.Sprintf("live-restore=%v/%s/%s", liveRestoreEnabled, c.desc, fnName), func(t *testing.T) { t.Run(fmt.Sprintf("live-restore=%v/%s/%s", liveRestoreEnabled, tc.desc, fnName), func(t *testing.T) {
c := c c := tc
liveRestoreEnabled := liveRestoreEnabled liveRestoreEnabled := liveRestoreEnabled
stopDaemon := stopDaemon stopDaemon := stopDaemon
t.Parallel() t.Parallel()
d := daemon.New(t) d := daemon.New(t)
client, err := d.NewClient() client := d.NewClientT(t)
assert.NilError(t, err)
args := []string{"--iptables=false"} args := []string{"--iptables=false"}
if liveRestoreEnabled { if liveRestoreEnabled {

View file

@ -32,19 +32,18 @@ func TestDockerNetworkIpvlanPersistance(t *testing.T) {
n.CreateMasterDummy(t, master) n.CreateMasterDummy(t, master)
defer n.DeleteInterface(t, master) defer n.DeleteInterface(t, master)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// create a network specifying the desired sub-interface name // create a network specifying the desired sub-interface name
netName := "di-persist" netName := "di-persist"
net.CreateNoError(t, context.Background(), client, netName, net.CreateNoError(t, context.Background(), c, netName,
net.WithIPvlan("di-dummy0.70", ""), net.WithIPvlan("di-dummy0.70", ""),
) )
assert.Check(t, n.IsNetworkAvailable(client, netName)) assert.Check(t, n.IsNetworkAvailable(c, netName))
// Restart docker daemon to test the config has persisted to disk // Restart docker daemon to test the config has persisted to disk
d.Restart(t) d.Restart(t)
assert.Check(t, n.IsNetworkAvailable(client, netName)) assert.Check(t, n.IsNetworkAvailable(c, netName))
} }
func TestDockerNetworkIpvlan(t *testing.T) { func TestDockerNetworkIpvlan(t *testing.T) {
@ -87,11 +86,9 @@ func TestDockerNetworkIpvlan(t *testing.T) {
} { } {
d := daemon.New(t, daemon.WithExperimental) d := daemon.New(t, daemon.WithExperimental)
d.StartWithBusybox(t) d.StartWithBusybox(t)
c := d.NewClientT(t)
client, err := d.NewClient() t.Run(tc.name, tc.test(c))
assert.NilError(t, err)
t.Run(tc.name, tc.test(client))
d.Stop(t) d.Stop(t)
// FIXME(vdemeester) clean network // FIXME(vdemeester) clean network

View file

@ -30,16 +30,15 @@ func TestDockerNetworkMacvlanPersistance(t *testing.T) {
n.CreateMasterDummy(t, master) n.CreateMasterDummy(t, master)
defer n.DeleteInterface(t, master) defer n.DeleteInterface(t, master)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
netName := "dm-persist" netName := "dm-persist"
net.CreateNoError(t, context.Background(), client, netName, net.CreateNoError(t, context.Background(), c, netName,
net.WithMacvlan("dm-dummy0.60"), net.WithMacvlan("dm-dummy0.60"),
) )
assert.Check(t, n.IsNetworkAvailable(client, netName)) assert.Check(t, n.IsNetworkAvailable(c, netName))
d.Restart(t) d.Restart(t)
assert.Check(t, n.IsNetworkAvailable(client, netName)) assert.Check(t, n.IsNetworkAvailable(c, netName))
} }
func TestDockerNetworkMacvlan(t *testing.T) { func TestDockerNetworkMacvlan(t *testing.T) {
@ -69,11 +68,9 @@ func TestDockerNetworkMacvlan(t *testing.T) {
} { } {
d := daemon.New(t) d := daemon.New(t)
d.StartWithBusybox(t) d.StartWithBusybox(t)
c := d.NewClientT(t)
client, err := d.NewClient() t.Run(tc.name, tc.test(c))
assert.NilError(t, err)
t.Run(tc.name, tc.test(client))
d.Stop(t) d.Stop(t)
// FIXME(vdemeester) clean network // FIXME(vdemeester) clean network

View file

@ -26,21 +26,20 @@ func TestRunContainerWithBridgeNone(t *testing.T) {
d.StartWithBusybox(t, "-b", "none") d.StartWithBusybox(t, "-b", "none")
defer d.Stop(t) defer d.Stop(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.Check(t, err, "error creating client")
ctx := context.Background() ctx := context.Background()
id1 := container.Run(t, ctx, client)
defer client.ContainerRemove(ctx, id1, types.ContainerRemoveOptions{Force: true})
result, err := container.Exec(ctx, client, id1, []string{"ip", "l"}) id1 := container.Run(t, ctx, c)
defer c.ContainerRemove(ctx, id1, types.ContainerRemoveOptions{Force: true})
result, err := container.Exec(ctx, c, id1, []string{"ip", "l"})
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled") assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled")
id2 := container.Run(t, ctx, client, container.WithNetworkMode("bridge")) id2 := container.Run(t, ctx, c, container.WithNetworkMode("bridge"))
defer client.ContainerRemove(ctx, id2, types.ContainerRemoveOptions{Force: true}) defer c.ContainerRemove(ctx, id2, types.ContainerRemoveOptions{Force: true})
result, err = container.Exec(ctx, client, id2, []string{"ip", "l"}) result, err = container.Exec(ctx, c, id2, []string{"ip", "l"})
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in bridge mode when bridge network is disabled") assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in bridge mode when bridge network is disabled")
@ -51,10 +50,10 @@ func TestRunContainerWithBridgeNone(t *testing.T) {
err = cmd.Run() err = cmd.Run()
assert.NilError(t, err, "Failed to get current process network namespace: %+v", err) assert.NilError(t, err, "Failed to get current process network namespace: %+v", err)
id3 := container.Run(t, ctx, client, container.WithNetworkMode("host")) id3 := container.Run(t, ctx, c, container.WithNetworkMode("host"))
defer client.ContainerRemove(ctx, id3, types.ContainerRemoveOptions{Force: true}) defer c.ContainerRemove(ctx, id3, types.ContainerRemoveOptions{Force: true})
result, err = container.Exec(ctx, client, id3, []string{"sh", "-c", nsCommand}) result, err = container.Exec(ctx, c, id3, []string{"sh", "-c", nsCommand})
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(stdout.String(), result.Combined()), "The network namspace of container should be the same with host when --net=host and bridge network is disabled") assert.Check(t, is.Equal(stdout.String(), result.Combined()), "The network namspace of container should be the same with host when --net=host and bridge network is disabled")
} }

View file

@ -32,15 +32,16 @@ func TestDaemonRestartWithLiveRestore(t *testing.T) {
d := daemon.New(t) d := daemon.New(t)
defer d.Stop(t) defer d.Stop(t)
d.Start(t) d.Start(t)
d.Restart(t, "--live-restore=true", d.Restart(t,
"--live-restore=true",
"--default-address-pool", "base=175.30.0.0/16,size=16", "--default-address-pool", "base=175.30.0.0/16,size=16",
"--default-address-pool", "base=175.33.0.0/16,size=24") "--default-address-pool", "base=175.33.0.0/16,size=24",
)
// Verify bridge network's subnet // Verify bridge network's subnet
cli, err := d.NewClient() c := d.NewClientT(t)
assert.Assert(t, err) defer c.Close()
defer cli.Close() out, err := c.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
out, err := cli.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
// Make sure docker0 doesn't get override with new IP in live restore case // Make sure docker0 doesn't get override with new IP in live restore case
assert.Equal(t, out.IPAM.Config[0].Subnet, "172.18.0.0/16") assert.Equal(t, out.IPAM.Config[0].Subnet, "172.18.0.0/16")
@ -57,31 +58,32 @@ func TestDaemonDefaultNetworkPools(t *testing.T) {
defer d.Stop(t) defer d.Stop(t)
d.Start(t, d.Start(t,
"--default-address-pool", "base=175.30.0.0/16,size=16", "--default-address-pool", "base=175.30.0.0/16,size=16",
"--default-address-pool", "base=175.33.0.0/16,size=24") "--default-address-pool", "base=175.33.0.0/16,size=24",
)
c := d.NewClientT(t)
defer c.Close()
// Verify bridge network's subnet // Verify bridge network's subnet
cli, err := d.NewClient() out, err := c.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
assert.Assert(t, err)
defer cli.Close()
out, err := cli.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, out.IPAM.Config[0].Subnet, "175.30.0.0/16") assert.Equal(t, out.IPAM.Config[0].Subnet, "175.30.0.0/16")
// Create a bridge network and verify its subnet is the second default pool // Create a bridge network and verify its subnet is the second default pool
name := "elango" + t.Name() name := "elango" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("bridge"), network.WithDriver("bridge"),
) )
out, err = cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{}) out, err = c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.0.0/24") assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.0.0/24")
// Create a bridge network and verify its subnet is the third default pool // Create a bridge network and verify its subnet is the third default pool
name = "saanvi" + t.Name() name = "saanvi" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("bridge"), network.WithDriver("bridge"),
) )
out, err = cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{}) out, err = c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.1.0/24") assert.Equal(t, out.IPAM.Config[0].Subnet, "175.33.1.0/24")
delInterface(t, defaultNetworkBridge) delInterface(t, defaultNetworkBridge)
@ -96,17 +98,17 @@ func TestDaemonRestartWithExistingNetwork(t *testing.T) {
d := daemon.New(t) d := daemon.New(t)
d.Start(t) d.Start(t)
defer d.Stop(t) defer d.Stop(t)
// Verify bridge network's subnet c := d.NewClientT(t)
cli, err := d.NewClient() defer c.Close()
assert.Assert(t, err)
defer cli.Close()
// Create a bridge network // Create a bridge network
name := "elango" + t.Name() name := "elango" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("bridge"), network.WithDriver("bridge"),
) )
out, err := cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
// Verify bridge network's subnet
out, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
networkip := out.IPAM.Config[0].Subnet networkip := out.IPAM.Config[0].Subnet
@ -115,7 +117,7 @@ func TestDaemonRestartWithExistingNetwork(t *testing.T) {
"--default-address-pool", "base=175.30.0.0/16,size=16", "--default-address-pool", "base=175.30.0.0/16,size=16",
"--default-address-pool", "base=175.33.0.0/16,size=24") "--default-address-pool", "base=175.33.0.0/16,size=24")
out1, err := cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{}) out1, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, out1.IPAM.Config[0].Subnet, networkip) assert.Equal(t, out1.IPAM.Config[0].Subnet, networkip)
delInterface(t, defaultNetworkBridge) delInterface(t, defaultNetworkBridge)
@ -129,40 +131,41 @@ func TestDaemonRestartWithExistingNetworkWithDefaultPoolRange(t *testing.T) {
d := daemon.New(t) d := daemon.New(t)
d.Start(t) d.Start(t)
defer d.Stop(t) defer d.Stop(t)
// Verify bridge network's subnet c := d.NewClientT(t)
cli, err := d.NewClient() defer c.Close()
assert.Assert(t, err)
defer cli.Close()
// Create a bridge network // Create a bridge network
name := "elango" + t.Name() name := "elango" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("bridge"), network.WithDriver("bridge"),
) )
out, err := cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
// Verify bridge network's subnet
out, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
networkip := out.IPAM.Config[0].Subnet networkip := out.IPAM.Config[0].Subnet
// Create a bridge network // Create a bridge network
name = "sthira" + t.Name() name = "sthira" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("bridge"), network.WithDriver("bridge"),
) )
out, err = cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{}) out, err = c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
networkip2 := out.IPAM.Config[0].Subnet networkip2 := out.IPAM.Config[0].Subnet
// Restart daemon with default address pool option // Restart daemon with default address pool option
d.Restart(t, d.Restart(t,
"--default-address-pool", "base=175.18.0.0/16,size=16", "--default-address-pool", "base=175.18.0.0/16,size=16",
"--default-address-pool", "base=175.19.0.0/16,size=24") "--default-address-pool", "base=175.19.0.0/16,size=24",
)
// Create a bridge network // Create a bridge network
name = "saanvi" + t.Name() name = "saanvi" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("bridge"), network.WithDriver("bridge"),
) )
out1, err := cli.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{}) out1, err := c.NetworkInspect(context.Background(), name, types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, out1.IPAM.Config[0].Subnet != networkip) assert.Check(t, out1.IPAM.Config[0].Subnet != networkip)
@ -177,15 +180,17 @@ func TestDaemonWithBipAndDefaultNetworkPool(t *testing.T) {
defaultNetworkBridge := "docker0" defaultNetworkBridge := "docker0"
d := daemon.New(t) d := daemon.New(t)
defer d.Stop(t) defer d.Stop(t)
d.Start(t, "--bip=172.60.0.1/16", d.Start(t,
"--bip=172.60.0.1/16",
"--default-address-pool", "base=175.30.0.0/16,size=16", "--default-address-pool", "base=175.30.0.0/16,size=16",
"--default-address-pool", "base=175.33.0.0/16,size=24") "--default-address-pool", "base=175.33.0.0/16,size=24",
)
c := d.NewClientT(t)
defer c.Close()
// Verify bridge network's subnet // Verify bridge network's subnet
cli, err := d.NewClient() out, err := c.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
assert.Assert(t, err)
defer cli.Close()
out, err := cli.NetworkInspect(context.Background(), "bridge", types.NetworkInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
// Make sure BIP IP doesn't get override with new default address pool . // Make sure BIP IP doesn't get override with new default address pool .
assert.Equal(t, out.IPAM.Config[0].Subnet, "172.60.0.1/16") assert.Equal(t, out.IPAM.Config[0].Subnet, "172.60.0.1/16")
@ -197,8 +202,8 @@ func TestServiceWithPredefinedNetwork(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 := d.NewClientT(t) c := d.NewClientT(t)
defer client.Close() defer c.Close()
hostName := "host" hostName := "host"
var instances uint64 = 1 var instances uint64 = 1
@ -210,12 +215,12 @@ func TestServiceWithPredefinedNetwork(t *testing.T) {
swarm.ServiceWithNetwork(hostName), swarm.ServiceWithNetwork(hostName),
) )
poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), swarm.ServicePoll) poll.WaitOn(t, serviceRunningCount(c, serviceID, instances), swarm.ServicePoll)
_, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) _, _, err := c.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
err = client.ServiceRemove(context.Background(), serviceID) err = c.ServiceRemove(context.Background(), serviceID)
assert.NilError(t, err) assert.NilError(t, err)
} }
@ -226,10 +231,10 @@ func TestServiceRemoveKeepsIngressNetwork(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 := d.NewClientT(t) c := d.NewClientT(t)
defer client.Close() defer c.Close()
poll.WaitOn(t, swarmIngressReady(client), swarm.NetworkPoll) poll.WaitOn(t, swarmIngressReady(c), swarm.NetworkPoll)
var instances uint64 = 1 var instances uint64 = 1
@ -247,20 +252,20 @@ func TestServiceRemoveKeepsIngressNetwork(t *testing.T) {
}), }),
) )
poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), swarm.ServicePoll) poll.WaitOn(t, serviceRunningCount(c, serviceID, instances), swarm.ServicePoll)
_, _, err := client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) _, _, err := c.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
err = client.ServiceRemove(context.Background(), serviceID) err = c.ServiceRemove(context.Background(), serviceID)
assert.NilError(t, err) assert.NilError(t, err)
poll.WaitOn(t, serviceIsRemoved(client, serviceID), swarm.ServicePoll) poll.WaitOn(t, serviceIsRemoved(c, serviceID), swarm.ServicePoll)
poll.WaitOn(t, noServices(client), swarm.ServicePoll) poll.WaitOn(t, noServices(c), swarm.ServicePoll)
// Ensure that "ingress" is not removed or corrupted // Ensure that "ingress" is not removed or corrupted
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
netInfo, err := client.NetworkInspect(context.Background(), ingressNet, types.NetworkInspectOptions{ netInfo, err := c.NetworkInspect(context.Background(), ingressNet, types.NetworkInspectOptions{
Verbose: true, Verbose: true,
Scope: "swarm", Scope: "swarm",
}) })
@ -330,12 +335,12 @@ func TestServiceWithDataPathPortInit(t *testing.T) {
ops = append(ops, daemon.WithSwarmDataPathPort(datapathPort)) ops = append(ops, daemon.WithSwarmDataPathPort(datapathPort))
d := swarm.NewSwarm(t, testEnv, ops...) d := swarm.NewSwarm(t, testEnv, ops...)
cli := d.NewClientT(t) c := d.NewClientT(t)
defer cli.Close() defer c.Close()
// Create a overlay network // Create a overlay network
name := "saanvisthira" + t.Name() name := "saanvisthira" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("overlay")) network.WithDriver("overlay"))
var instances uint64 = 1 var instances uint64 = 1
@ -344,11 +349,11 @@ func TestServiceWithDataPathPortInit(t *testing.T) {
swarm.ServiceWithNetwork(name), swarm.ServiceWithNetwork(name),
) )
poll.WaitOn(t, serviceRunningCount(cli, serviceID, instances), swarm.ServicePoll) poll.WaitOn(t, serviceRunningCount(c, serviceID, instances), swarm.ServicePoll)
info := d.Info(t) info := d.Info(t)
assert.Equal(t, info.Swarm.Cluster.DataPathPort, datapathPort) assert.Equal(t, info.Swarm.Cluster.DataPathPort, datapathPort)
err := cli.ServiceRemove(context.Background(), serviceID) err := c.ServiceRemove(context.Background(), serviceID)
assert.NilError(t, err) assert.NilError(t, err)
d.SwarmLeave(true) d.SwarmLeave(true)
d.Stop(t) d.Stop(t)
@ -357,11 +362,11 @@ func TestServiceWithDataPathPortInit(t *testing.T) {
// call without datapath port option. // call without datapath port option.
ops = []func(*daemon.Daemon){} ops = []func(*daemon.Daemon){}
d = swarm.NewSwarm(t, testEnv, ops...) d = swarm.NewSwarm(t, testEnv, ops...)
cli = d.NewClientT(t) c = d.NewClientT(t)
// Create a overlay network // Create a overlay network
name = "saanvisthira" + t.Name() name = "saanvisthira" + t.Name()
network.CreateNoError(t, context.Background(), cli, name, network.CreateNoError(t, context.Background(), c, name,
network.WithDriver("overlay")) network.WithDriver("overlay"))
serviceID = swarm.CreateService(t, d, serviceID = swarm.CreateService(t, d,
@ -369,12 +374,12 @@ func TestServiceWithDataPathPortInit(t *testing.T) {
swarm.ServiceWithNetwork(name), swarm.ServiceWithNetwork(name),
) )
poll.WaitOn(t, serviceRunningCount(cli, serviceID, instances), swarm.ServicePoll) poll.WaitOn(t, serviceRunningCount(c, serviceID, instances), swarm.ServicePoll)
info = d.Info(t) info = d.Info(t)
var defaultDataPathPort uint32 = 4789 var defaultDataPathPort uint32 = 4789
assert.Equal(t, info.Swarm.Cluster.DataPathPort, defaultDataPathPort) assert.Equal(t, info.Swarm.Cluster.DataPathPort, defaultDataPathPort)
err = cli.ServiceRemove(context.Background(), serviceID) err = c.ServiceRemove(context.Background(), serviceID)
assert.NilError(t, err) assert.NilError(t, err)
d.SwarmLeave(true) d.SwarmLeave(true)
defer d.Stop(t) defer d.Stop(t)

View file

@ -87,18 +87,16 @@ func TestAuthZPluginAllowRequest(t *testing.T) {
ctrl.resRes.Allow = true ctrl.resRes.Allow = true
d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin) d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
ctx := context.Background() ctx := context.Background()
// Ensure command successful // Ensure command successful
cID := container.Run(t, ctx, client) cID := container.Run(t, ctx, c)
assertURIRecorded(t, ctrl.requestsURIs, "/containers/create") assertURIRecorded(t, ctrl.requestsURIs, "/containers/create")
assertURIRecorded(t, ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", cID)) assertURIRecorded(t, ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", cID))
_, err = client.ServerVersion(ctx) _, err := c.ServerVersion(ctx)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, 1, ctrl.versionReqCount) assert.Equal(t, 1, ctrl.versionReqCount)
assert.Equal(t, 1, ctrl.versionResCount) assert.Equal(t, 1, ctrl.versionResCount)
@ -126,10 +124,10 @@ func TestAuthZPluginTLS(t *testing.T) {
ctrl.reqRes.Allow = true ctrl.reqRes.Allow = true
ctrl.resRes.Allow = true ctrl.resRes.Allow = true
client, err := newTLSAPIClient(testDaemonHTTPSAddr, cacertPath, clientCertPath, clientKeyPath) c, err := newTLSAPIClient(testDaemonHTTPSAddr, cacertPath, clientCertPath, clientKeyPath)
assert.NilError(t, err) assert.NilError(t, err)
_, err = client.ServerVersion(context.Background()) _, err = c.ServerVersion(context.Background())
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, "client", ctrl.reqUser) assert.Equal(t, "client", ctrl.reqUser)
@ -153,11 +151,10 @@ func TestAuthZPluginDenyRequest(t *testing.T) {
ctrl.reqRes.Allow = false ctrl.reqRes.Allow = false
ctrl.reqRes.Msg = unauthorizedMessage ctrl.reqRes.Msg = unauthorizedMessage
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Ensure command is blocked // Ensure command is blocked
_, err = client.ServerVersion(context.Background()) _, err := c.ServerVersion(context.Background())
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Equal(t, 1, ctrl.versionReqCount) assert.Equal(t, 1, ctrl.versionReqCount)
assert.Equal(t, 0, ctrl.versionResCount) assert.Equal(t, 0, ctrl.versionResCount)
@ -179,10 +176,10 @@ func TestAuthZPluginAPIDenyResponse(t *testing.T) {
conn, err := net.DialTimeout(daemonURL.Scheme, daemonURL.Path, time.Second*10) conn, err := net.DialTimeout(daemonURL.Scheme, daemonURL.Path, time.Second*10)
assert.NilError(t, err) assert.NilError(t, err)
client := httputil.NewClientConn(conn, nil) c := httputil.NewClientConn(conn, nil)
req, err := http.NewRequest("GET", "/version", nil) req, err := http.NewRequest("GET", "/version", nil)
assert.NilError(t, err) assert.NilError(t, err)
resp, err := client.Do(req) resp, err := c.Do(req)
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, http.StatusForbidden, resp.StatusCode) assert.DeepEqual(t, http.StatusForbidden, resp.StatusCode)
@ -195,11 +192,10 @@ func TestAuthZPluginDenyResponse(t *testing.T) {
ctrl.resRes.Allow = false ctrl.resRes.Allow = false
ctrl.resRes.Msg = unauthorizedMessage ctrl.resRes.Msg = unauthorizedMessage
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Ensure command is blocked // Ensure command is blocked
_, err = client.ServerVersion(context.Background()) _, err := c.ServerVersion(context.Background())
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Equal(t, 1, ctrl.versionReqCount) assert.Equal(t, 1, ctrl.versionReqCount)
assert.Equal(t, 1, ctrl.versionResCount) assert.Equal(t, 1, ctrl.versionResCount)
@ -219,20 +215,18 @@ func TestAuthZPluginAllowEventStream(t *testing.T) {
ctrl.resRes.Allow = true ctrl.resRes.Allow = true
d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin) d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
ctx := context.Background() ctx := context.Background()
startTime := strconv.FormatInt(systemTime(t, client, testEnv).Unix(), 10) startTime := strconv.FormatInt(systemTime(t, c, testEnv).Unix(), 10)
events, errs, cancel := systemEventsSince(client, startTime) events, errs, cancel := systemEventsSince(c, startTime)
defer cancel() defer cancel()
// Create a container and wait for the creation events // Create a container and wait for the creation events
cID := container.Run(t, ctx, client) cID := container.Run(t, ctx, c)
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
c, err := client.ContainerInspect(ctx, cID) c, err := c.ContainerInspect(ctx, cID)
assert.NilError(t, err) assert.NilError(t, err)
if c.State.Running { if c.State.Running {
break break
@ -304,11 +298,10 @@ func TestAuthZPluginErrorResponse(t *testing.T) {
ctrl.reqRes.Allow = true ctrl.reqRes.Allow = true
ctrl.resRes.Err = errorMessage ctrl.resRes.Err = errorMessage
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Ensure command is blocked // Ensure command is blocked
_, err = client.ServerVersion(context.Background()) _, err := c.ServerVersion(context.Background())
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiResponse, errorMessage), err.Error()) assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiResponse, errorMessage), err.Error())
} }
@ -318,11 +311,10 @@ func TestAuthZPluginErrorRequest(t *testing.T) {
d.Start(t, "--authorization-plugin="+testAuthZPlugin) d.Start(t, "--authorization-plugin="+testAuthZPlugin)
ctrl.reqRes.Err = errorMessage ctrl.reqRes.Err = errorMessage
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Ensure command is blocked // Ensure command is blocked
_, err = client.ServerVersion(context.Background()) _, err := c.ServerVersion(context.Background())
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiRequest, errorMessage), err.Error()) assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiRequest, errorMessage), err.Error())
} }
@ -334,10 +326,9 @@ func TestAuthZPluginEnsureNoDuplicatePluginRegistration(t *testing.T) {
ctrl.reqRes.Allow = true ctrl.reqRes.Allow = true
ctrl.resRes.Allow = true ctrl.resRes.Allow = true
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
_, err = client.ServerVersion(context.Background()) _, err := c.ServerVersion(context.Background())
assert.NilError(t, err) assert.NilError(t, err)
// assert plugin is only called once.. // assert plugin is only called once..
@ -351,9 +342,7 @@ func TestAuthZPluginEnsureLoadImportWorking(t *testing.T) {
ctrl.resRes.Allow = true ctrl.resRes.Allow = true
d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin) d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
ctx := context.Background() ctx := context.Background()
tmp, err := ioutil.TempDir("", "test-authz-load-import") tmp, err := ioutil.TempDir("", "test-authz-load-import")
@ -362,16 +351,16 @@ func TestAuthZPluginEnsureLoadImportWorking(t *testing.T) {
savedImagePath := filepath.Join(tmp, "save.tar") savedImagePath := filepath.Join(tmp, "save.tar")
err = imageSave(client, savedImagePath, "busybox") err = imageSave(c, savedImagePath, "busybox")
assert.NilError(t, err) assert.NilError(t, err)
err = imageLoad(client, savedImagePath) err = imageLoad(c, savedImagePath)
assert.NilError(t, err) assert.NilError(t, err)
exportedImagePath := filepath.Join(tmp, "export.tar") exportedImagePath := filepath.Join(tmp, "export.tar")
cID := container.Run(t, ctx, client) cID := container.Run(t, ctx, c)
responseReader, err := client.ContainerExport(context.Background(), cID) responseReader, err := c.ContainerExport(context.Background(), cID)
assert.NilError(t, err) assert.NilError(t, err)
defer responseReader.Close() defer responseReader.Close()
file, err := os.Create(exportedImagePath) file, err := os.Create(exportedImagePath)
@ -380,7 +369,7 @@ func TestAuthZPluginEnsureLoadImportWorking(t *testing.T) {
_, err = io.Copy(file, responseReader) _, err = io.Copy(file, responseReader)
assert.NilError(t, err) assert.NilError(t, err)
err = imageImport(client, exportedImagePath) err = imageImport(c, exportedImagePath)
assert.NilError(t, err) assert.NilError(t, err)
} }
@ -406,12 +395,11 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
written += n written += n
} }
c := d.NewClientT(t)
ctx := context.Background() ctx := context.Background()
client, err := d.NewClient()
assert.Assert(t, err)
cID := container.Run(t, ctx, client) cID := container.Run(t, ctx, c)
defer client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
_, err = f.Seek(0, io.SeekStart) _, err = f.Seek(0, io.SeekStart)
assert.Assert(t, err) assert.Assert(t, err)
@ -425,10 +413,10 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: "/test"}) dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: "/test"})
assert.Assert(t, err) assert.Assert(t, err)
err = client.CopyToContainer(ctx, cID, dstDir, preparedArchive, types.CopyToContainerOptions{}) err = c.CopyToContainer(ctx, cID, dstDir, preparedArchive, types.CopyToContainerOptions{})
assert.Assert(t, err) assert.Assert(t, err)
rdr, _, err := client.CopyFromContainer(ctx, cID, "/test") rdr, _, err := c.CopyFromContainer(ctx, cID, "/test")
assert.Assert(t, err) assert.Assert(t, err)
_, err = io.Copy(ioutil.Discard, rdr) _, err = io.Copy(ioutil.Discard, rdr)
assert.Assert(t, err) assert.Assert(t, err)

View file

@ -43,13 +43,11 @@ func TestAuthZPluginV2AllowNonVolumeRequest(t *testing.T) {
skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64") skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64")
defer setupTestV2(t)() defer setupTestV2(t)()
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
ctx := context.Background() ctx := context.Background()
// Install authz plugin // Install authz plugin
err = pluginInstallGrantAllPermissions(client, authzPluginNameWithTag) err := pluginInstallGrantAllPermissions(c, authzPluginNameWithTag)
assert.NilError(t, err) assert.NilError(t, err)
// start the daemon with the plugin and load busybox, --net=none build fails otherwise // start the daemon with the plugin and load busybox, --net=none build fails otherwise
// because it needs to pull busybox // because it needs to pull busybox
@ -57,9 +55,9 @@ func TestAuthZPluginV2AllowNonVolumeRequest(t *testing.T) {
d.LoadBusybox(t) d.LoadBusybox(t)
// Ensure docker run command and accompanying docker ps are successful // Ensure docker run command and accompanying docker ps are successful
cID := container.Run(t, ctx, client) cID := container.Run(t, ctx, c)
_, err = client.ContainerInspect(ctx, cID) _, err = c.ContainerInspect(ctx, cID)
assert.NilError(t, err) assert.NilError(t, err)
} }
@ -67,26 +65,25 @@ func TestAuthZPluginV2Disable(t *testing.T) {
skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64") skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64")
defer setupTestV2(t)() defer setupTestV2(t)()
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Install authz plugin // Install authz plugin
err = pluginInstallGrantAllPermissions(client, authzPluginNameWithTag) err := pluginInstallGrantAllPermissions(c, authzPluginNameWithTag)
assert.NilError(t, err) assert.NilError(t, err)
d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag) d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag)
d.LoadBusybox(t) d.LoadBusybox(t)
_, err = client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{Driver: "local"}) _, err = c.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{Driver: "local"})
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)))
// disable the plugin // disable the plugin
err = client.PluginDisable(context.Background(), authzPluginNameWithTag, types.PluginDisableOptions{}) err = c.PluginDisable(context.Background(), authzPluginNameWithTag, types.PluginDisableOptions{})
assert.NilError(t, err) assert.NilError(t, err)
// now test to see if the docker api works. // now test to see if the docker api works.
_, err = client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{Driver: "local"}) _, err = c.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{Driver: "local"})
assert.NilError(t, err) assert.NilError(t, err)
} }
@ -94,34 +91,33 @@ func TestAuthZPluginV2RejectVolumeRequests(t *testing.T) {
skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64") skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64")
defer setupTestV2(t)() defer setupTestV2(t)()
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Install authz plugin // Install authz plugin
err = pluginInstallGrantAllPermissions(client, authzPluginNameWithTag) err := pluginInstallGrantAllPermissions(c, authzPluginNameWithTag)
assert.NilError(t, err) assert.NilError(t, err)
// restart the daemon with the plugin // restart the daemon with the plugin
d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag) d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag)
_, err = client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{Driver: "local"}) _, err = c.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{Driver: "local"})
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)))
_, err = client.VolumeList(context.Background(), filters.Args{}) _, err = c.VolumeList(context.Background(), filters.Args{})
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)))
// The plugin will block the command before it can determine the volume does not exist // The plugin will block the command before it can determine the volume does not exist
err = client.VolumeRemove(context.Background(), "test", false) err = c.VolumeRemove(context.Background(), "test", false)
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)))
_, err = client.VolumeInspect(context.Background(), "test") _, err = c.VolumeInspect(context.Background(), "test")
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)))
_, err = client.VolumesPrune(context.Background(), filters.Args{}) _, err = c.VolumesPrune(context.Background(), filters.Args{})
assert.Assert(t, err != nil) assert.Assert(t, err != nil)
assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag)))
} }
@ -130,11 +126,10 @@ func TestAuthZPluginV2BadManifestFailsDaemonStart(t *testing.T) {
skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64") skip.If(t, os.Getenv("DOCKER_ENGINE_GOARCH") != "amd64")
defer setupTestV2(t)() defer setupTestV2(t)()
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
// Install authz plugin with bad manifest // Install authz plugin with bad manifest
err = pluginInstallGrantAllPermissions(client, authzPluginBadManifestName) err := pluginInstallGrantAllPermissions(c, authzPluginBadManifestName)
assert.NilError(t, err) assert.NilError(t, err)
// start the daemon with the plugin, it will error // start the daemon with the plugin, it will error

View file

@ -24,14 +24,13 @@ func TestDaemonStartWithLogOpt(t *testing.T) {
d.Start(t, "--iptables=false") d.Start(t, "--iptables=false")
defer d.Stop(t) defer d.Stop(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.Check(t, err)
ctx := context.Background() ctx := context.Background()
createPlugin(t, client, "test", "dummy", asLogDriver) createPlugin(t, c, "test", "dummy", asLogDriver)
err = client.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30}) err := c.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30})
assert.Check(t, err) assert.Check(t, err)
defer client.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true}) defer c.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true})
d.Stop(t) d.Stop(t)
d.Start(t, "--iptables=false", "--log-driver=test", "--log-opt=foo=bar") d.Start(t, "--iptables=false", "--log-driver=test", "--log-opt=foo=bar")

View file

@ -24,15 +24,14 @@ func TestPluginWithDevMounts(t *testing.T) {
d.Start(t, "--iptables=false") d.Start(t, "--iptables=false")
defer d.Stop(t) defer d.Stop(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.Assert(t, err)
ctx := context.Background() ctx := context.Background()
testDir, err := ioutil.TempDir("", "test-dir") testDir, err := ioutil.TempDir("", "test-dir")
assert.Assert(t, err) assert.Assert(t, err)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
createPlugin(t, client, "test", "dummy", asVolumeDriver, func(c *plugin.Config) { createPlugin(t, c, "test", "dummy", asVolumeDriver, func(c *plugin.Config) {
root := "/" root := "/"
dev := "/dev" dev := "/dev"
mounts := []types.PluginMount{ mounts := []types.PluginMount{
@ -46,14 +45,14 @@ func TestPluginWithDevMounts(t *testing.T) {
c.IpcHost = true c.IpcHost = true
}) })
err = client.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30}) err = c.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30})
assert.Assert(t, err) assert.Assert(t, err)
defer func() { defer func() {
err := client.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true}) err := c.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true})
assert.Check(t, err) assert.Check(t, err)
}() }()
p, _, err := client.PluginInspectWithRaw(ctx, "test") p, _, err := c.PluginInspectWithRaw(ctx, "test")
assert.Assert(t, err) assert.Assert(t, err)
assert.Assert(t, p.Enabled) assert.Assert(t, p.Enabled)
} }

View file

@ -36,23 +36,23 @@ func TestCgroupDriverSystemdMemoryLimit(t *testing.T) {
} }
d := daemon.New(t) d := daemon.New(t)
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err)
d.StartWithBusybox(t, "--exec-opt", "native.cgroupdriver=systemd", "--iptables=false") d.StartWithBusybox(t, "--exec-opt", "native.cgroupdriver=systemd", "--iptables=false")
defer d.Stop(t) defer d.Stop(t)
const mem = 64 * 1024 * 1024 // 64 MB const mem = 64 * 1024 * 1024 // 64 MB
ctx := context.Background() ctx := context.Background()
ctrID := container.Create(t, ctx, client, func(c *container.TestContainerConfig) { ctrID := container.Create(t, ctx, c, func(ctr *container.TestContainerConfig) {
c.HostConfig.Resources.Memory = mem ctr.HostConfig.Resources.Memory = mem
}) })
defer client.ContainerRemove(ctx, ctrID, types.ContainerRemoveOptions{Force: true}) defer c.ContainerRemove(ctx, ctrID, types.ContainerRemoveOptions{Force: true})
err = client.ContainerStart(ctx, ctrID, types.ContainerStartOptions{}) err := c.ContainerStart(ctx, ctrID, types.ContainerStartOptions{})
assert.NilError(t, err) assert.NilError(t, err)
s, err := client.ContainerInspect(ctx, ctrID) s, err := c.ContainerInspect(ctx, ctrID)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, s.HostConfig.Memory, mem) assert.Equal(t, s.HostConfig.Memory, mem)
} }

View file

@ -46,14 +46,12 @@ func TestInfoAPI(t *testing.T) {
func TestInfoAPIWarnings(t *testing.T) { func TestInfoAPIWarnings(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME") skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
d := daemon.New(t) d := daemon.New(t)
c := d.NewClientT(t)
client, err := d.NewClient()
assert.NilError(t, err)
d.StartWithBusybox(t, "-H=0.0.0.0:23756", "-H="+d.Sock()) d.StartWithBusybox(t, "-H=0.0.0.0:23756", "-H="+d.Sock())
defer d.Stop(t) defer d.Stop(t)
info, err := client.Info(context.Background()) info, err := c.Info(context.Background())
assert.NilError(t, err) assert.NilError(t, err)
stringsToCheck := []string{ stringsToCheck := []string{

View file

@ -568,11 +568,10 @@ func (d *Daemon) LoadBusybox(t assert.TestingT) {
assert.NilError(t, err, "failed to download busybox") assert.NilError(t, err, "failed to download busybox")
defer reader.Close() defer reader.Close()
client, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err, "failed to create client") defer c.Close()
defer client.Close()
resp, err := client.ImageLoad(ctx, reader, true) resp, err := c.ImageLoad(ctx, reader, true)
assert.NilError(t, err, "failed to load busybox") assert.NilError(t, err, "failed to load busybox")
defer resp.Body.Close() defer resp.Body.Close()
} }
@ -632,7 +631,7 @@ func (d *Daemon) queryRootDir() (string, error) {
return "", err return "", err
} }
client := &http.Client{ c := &http.Client{
Transport: clientConfig.transport, Transport: clientConfig.transport,
} }
@ -644,7 +643,7 @@ func (d *Daemon) queryRootDir() (string, error) {
req.URL.Host = clientConfig.addr req.URL.Host = clientConfig.addr
req.URL.Scheme = clientConfig.scheme req.URL.Scheme = clientConfig.scheme
resp, err := client.Do(req) resp, err := c.Do(req)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -672,9 +671,8 @@ func (d *Daemon) Info(t assert.TestingT) types.Info {
if ht, ok := t.(test.HelperT); ok { if ht, ok := t.(test.HelperT); ok {
ht.Helper() ht.Helper()
} }
apiclient, err := d.NewClient() c := d.NewClientT(t)
assert.NilError(t, err) info, err := c.Info(context.Background())
info, err := apiclient.Info(context.Background())
assert.NilError(t, err) assert.NilError(t, err)
return info return info
} }