From 41adef29f57b0050c4e9c6c9606fae2b7ddf129b Mon Sep 17 00:00:00 2001 From: Sam Whited Date: Tue, 17 Sep 2019 12:44:35 -0500 Subject: [PATCH] testutil/daemon: group options under type Signed-off-by: Sam Whited --- integration-cli/daemon/daemon.go | 2 +- integration/internal/swarm/service.go | 2 +- integration/service/create_test.go | 2 +- testutil/daemon/daemon.go | 2 +- testutil/daemon/ops.go | 19 +++++++++++-------- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/integration-cli/daemon/daemon.go b/integration-cli/daemon/daemon.go index d138f85ce5..87cb829a08 100644 --- a/integration-cli/daemon/daemon.go +++ b/integration-cli/daemon/daemon.go @@ -31,7 +31,7 @@ type Daemon struct { // New returns a Daemon instance to be used for testing. // This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. // The daemon will not automatically start. -func New(t testingT, dockerBinary string, dockerdBinary string, ops ...func(*daemon.Daemon)) *Daemon { +func New(t testingT, dockerBinary string, dockerdBinary string, ops ...daemon.Option) *Daemon { ops = append(ops, daemon.WithDockerdBinary(dockerdBinary)) d := daemon.New(t, ops...) return &Daemon{ diff --git a/integration/internal/swarm/service.go b/integration/internal/swarm/service.go index e7198266e6..a9df58329b 100644 --- a/integration/internal/swarm/service.go +++ b/integration/internal/swarm/service.go @@ -49,7 +49,7 @@ func ContainerPoll(config *poll.Settings) { } // NewSwarm creates a swarm daemon for testing -func NewSwarm(t *testing.T, testEnv *environment.Execution, ops ...func(*daemon.Daemon)) *daemon.Daemon { +func NewSwarm(t *testing.T, testEnv *environment.Execution, ops ...daemon.Option) *daemon.Daemon { t.Helper() skip.If(t, testEnv.IsRemoteDaemon) skip.If(t, testEnv.DaemonInfo.OSType == "windows") diff --git a/integration/service/create_test.go b/integration/service/create_test.go index ecc7f5565c..43da879566 100644 --- a/integration/service/create_test.go +++ b/integration/service/create_test.go @@ -30,7 +30,7 @@ func TestServiceCreateInit(t *testing.T) { func testServiceCreateInit(daemonEnabled bool) func(t *testing.T) { return func(t *testing.T) { - var ops = []func(*daemon.Daemon){} + var ops = []daemon.Option{} if daemonEnabled { ops = append(ops, daemon.WithInit) diff --git a/testutil/daemon/daemon.go b/testutil/daemon/daemon.go index 544fae299b..7ca708db7d 100644 --- a/testutil/daemon/daemon.go +++ b/testutil/daemon/daemon.go @@ -94,7 +94,7 @@ type Daemon struct { // New returns a Daemon instance to be used for testing. // This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. // The daemon will not automatically start. -func New(t testingT, ops ...func(*Daemon)) *Daemon { +func New(t testingT, ops ...Option) *Daemon { if ht, ok := t.(testutil.HelperT); ok { ht.Helper() } diff --git a/testutil/daemon/ops.go b/testutil/daemon/ops.go index 546c639c09..d1e7d8343c 100644 --- a/testutil/daemon/ops.go +++ b/testutil/daemon/ops.go @@ -2,8 +2,11 @@ package daemon import "github.com/docker/docker/testutil/environment" +// Option is used to configure a daemon. +type Option func(*Daemon) + // WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon -func WithDefaultCgroupNamespaceMode(mode string) func(*Daemon) { +func WithDefaultCgroupNamespaceMode(mode string) Option { return func(d *Daemon) { d.defaultCgroupNamespaceMode = mode } @@ -21,49 +24,49 @@ func WithInit(d *Daemon) { } // WithDockerdBinary sets the dockerd binary to the specified one -func WithDockerdBinary(dockerdBinary string) func(*Daemon) { +func WithDockerdBinary(dockerdBinary string) Option { return func(d *Daemon) { d.dockerdBinary = dockerdBinary } } // WithSwarmPort sets the swarm port to use for swarm mode -func WithSwarmPort(port int) func(*Daemon) { +func WithSwarmPort(port int) Option { return func(d *Daemon) { d.SwarmPort = port } } // WithSwarmListenAddr sets the swarm listen addr to use for swarm mode -func WithSwarmListenAddr(listenAddr string) func(*Daemon) { +func WithSwarmListenAddr(listenAddr string) Option { return func(d *Daemon) { d.swarmListenAddr = listenAddr } } // WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode -func WithSwarmDefaultAddrPool(defaultAddrPool []string) func(*Daemon) { +func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option { return func(d *Daemon) { d.DefaultAddrPool = defaultAddrPool } } // WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode -func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) func(*Daemon) { +func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option { return func(d *Daemon) { d.SubnetSize = subnetSize } } // WithSwarmDataPathPort sets the swarm datapath port to use for swarm mode -func WithSwarmDataPathPort(datapathPort uint32) func(*Daemon) { +func WithSwarmDataPathPort(datapathPort uint32) Option { return func(d *Daemon) { d.DataPathPort = datapathPort } } // WithEnvironment sets options from testutil/environment.Execution struct -func WithEnvironment(e environment.Execution) func(*Daemon) { +func WithEnvironment(e environment.Execution) Option { return func(d *Daemon) { if e.DaemonInfo.ExperimentalBuild { d.experimental = true