Signed-off-by: Sam Whited <sam@samwhited.com>
| ... | ... |
@@ -31,7 +31,7 @@ type Daemon struct {
|
| 31 | 31 |
// New returns a Daemon instance to be used for testing. |
| 32 | 32 |
// This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. |
| 33 | 33 |
// The daemon will not automatically start. |
| 34 |
-func New(t testingT, dockerBinary string, dockerdBinary string, ops ...func(*daemon.Daemon)) *Daemon {
|
|
| 34 |
+func New(t testingT, dockerBinary string, dockerdBinary string, ops ...daemon.Option) *Daemon {
|
|
| 35 | 35 |
ops = append(ops, daemon.WithDockerdBinary(dockerdBinary)) |
| 36 | 36 |
d := daemon.New(t, ops...) |
| 37 | 37 |
return &Daemon{
|
| ... | ... |
@@ -49,7 +49,7 @@ func ContainerPoll(config *poll.Settings) {
|
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
// NewSwarm creates a swarm daemon for testing |
| 52 |
-func NewSwarm(t *testing.T, testEnv *environment.Execution, ops ...func(*daemon.Daemon)) *daemon.Daemon {
|
|
| 52 |
+func NewSwarm(t *testing.T, testEnv *environment.Execution, ops ...daemon.Option) *daemon.Daemon {
|
|
| 53 | 53 |
t.Helper() |
| 54 | 54 |
skip.If(t, testEnv.IsRemoteDaemon) |
| 55 | 55 |
skip.If(t, testEnv.DaemonInfo.OSType == "windows") |
| ... | ... |
@@ -30,7 +30,7 @@ func TestServiceCreateInit(t *testing.T) {
|
| 30 | 30 |
|
| 31 | 31 |
func testServiceCreateInit(daemonEnabled bool) func(t *testing.T) {
|
| 32 | 32 |
return func(t *testing.T) {
|
| 33 |
- var ops = []func(*daemon.Daemon){}
|
|
| 33 |
+ var ops = []daemon.Option{}
|
|
| 34 | 34 |
|
| 35 | 35 |
if daemonEnabled {
|
| 36 | 36 |
ops = append(ops, daemon.WithInit) |
| ... | ... |
@@ -94,7 +94,7 @@ type Daemon struct {
|
| 94 | 94 |
// New returns a Daemon instance to be used for testing. |
| 95 | 95 |
// This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. |
| 96 | 96 |
// The daemon will not automatically start. |
| 97 |
-func New(t testingT, ops ...func(*Daemon)) *Daemon {
|
|
| 97 |
+func New(t testingT, ops ...Option) *Daemon {
|
|
| 98 | 98 |
if ht, ok := t.(testutil.HelperT); ok {
|
| 99 | 99 |
ht.Helper() |
| 100 | 100 |
} |
| ... | ... |
@@ -2,8 +2,11 @@ package daemon |
| 2 | 2 |
|
| 3 | 3 |
import "github.com/docker/docker/testutil/environment" |
| 4 | 4 |
|
| 5 |
+// Option is used to configure a daemon. |
|
| 6 |
+type Option func(*Daemon) |
|
| 7 |
+ |
|
| 5 | 8 |
// WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon |
| 6 |
-func WithDefaultCgroupNamespaceMode(mode string) func(*Daemon) {
|
|
| 9 |
+func WithDefaultCgroupNamespaceMode(mode string) Option {
|
|
| 7 | 10 |
return func(d *Daemon) {
|
| 8 | 11 |
d.defaultCgroupNamespaceMode = mode |
| 9 | 12 |
} |
| ... | ... |
@@ -21,49 +24,49 @@ func WithInit(d *Daemon) {
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
// WithDockerdBinary sets the dockerd binary to the specified one |
| 24 |
-func WithDockerdBinary(dockerdBinary string) func(*Daemon) {
|
|
| 24 |
+func WithDockerdBinary(dockerdBinary string) Option {
|
|
| 25 | 25 |
return func(d *Daemon) {
|
| 26 | 26 |
d.dockerdBinary = dockerdBinary |
| 27 | 27 |
} |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
// WithSwarmPort sets the swarm port to use for swarm mode |
| 31 |
-func WithSwarmPort(port int) func(*Daemon) {
|
|
| 31 |
+func WithSwarmPort(port int) Option {
|
|
| 32 | 32 |
return func(d *Daemon) {
|
| 33 | 33 |
d.SwarmPort = port |
| 34 | 34 |
} |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
// WithSwarmListenAddr sets the swarm listen addr to use for swarm mode |
| 38 |
-func WithSwarmListenAddr(listenAddr string) func(*Daemon) {
|
|
| 38 |
+func WithSwarmListenAddr(listenAddr string) Option {
|
|
| 39 | 39 |
return func(d *Daemon) {
|
| 40 | 40 |
d.swarmListenAddr = listenAddr |
| 41 | 41 |
} |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 | 44 |
// WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode |
| 45 |
-func WithSwarmDefaultAddrPool(defaultAddrPool []string) func(*Daemon) {
|
|
| 45 |
+func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option {
|
|
| 46 | 46 |
return func(d *Daemon) {
|
| 47 | 47 |
d.DefaultAddrPool = defaultAddrPool |
| 48 | 48 |
} |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
// WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode |
| 52 |
-func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) func(*Daemon) {
|
|
| 52 |
+func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option {
|
|
| 53 | 53 |
return func(d *Daemon) {
|
| 54 | 54 |
d.SubnetSize = subnetSize |
| 55 | 55 |
} |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 | 58 |
// WithSwarmDataPathPort sets the swarm datapath port to use for swarm mode |
| 59 |
-func WithSwarmDataPathPort(datapathPort uint32) func(*Daemon) {
|
|
| 59 |
+func WithSwarmDataPathPort(datapathPort uint32) Option {
|
|
| 60 | 60 |
return func(d *Daemon) {
|
| 61 | 61 |
d.DataPathPort = datapathPort |
| 62 | 62 |
} |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
// WithEnvironment sets options from testutil/environment.Execution struct |
| 66 |
-func WithEnvironment(e environment.Execution) func(*Daemon) {
|
|
| 66 |
+func WithEnvironment(e environment.Execution) Option {
|
|
| 67 | 67 |
return func(d *Daemon) {
|
| 68 | 68 |
if e.DaemonInfo.ExperimentalBuild {
|
| 69 | 69 |
d.experimental = true |