-
Notifications
You must be signed in to change notification settings - Fork 15
/
options.go
72 lines (66 loc) · 1.94 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package dktest
import (
"context"
"time"
"github.com/docker/docker/api/types/mount"
"github.com/docker/go-connections/nat"
)
// Options contains the configurable options for running tests in the docker image
type Options struct {
// PullTimeout is the timeout used when pulling images
PullTimeout time.Duration
// Timeout is the timeout used when starting a container and checking if it's ready
Timeout time.Duration
// ReadyTimeout is the timeout used for each container ready check.
// e.g. each invocation of the ReadyFunc
ReadyTimeout time.Duration
// CleanupTimeout is the timeout used when stopping and removing a container
CleanupTimeout time.Duration
// CleanupImage specifies whether or not the image should be removed after the test run.
// If the image is used by multiple tests, you'll want to cleanup the image yourself.
CleanupImage bool
ReadyFunc func(context.Context, ContainerInfo) bool
Env map[string]string
Entrypoint []string
Cmd []string
// If you prefer to specify your port bindings as a string, use nat.ParsePortSpecs()
PortBindings nat.PortMap
PortRequired bool
LogStdout bool
LogStderr bool
ShmSize int64
Volumes []string
Mounts []mount.Mount
Hostname string
// Platform specifies the platform of the docker image that is pulled.
Platform string
ExposedPorts nat.PortSet
}
func (o *Options) init() {
if o.PullTimeout <= 0 {
o.PullTimeout = DefaultPullTimeout
}
if o.Timeout <= 0 {
o.Timeout = DefaultTimeout
}
if o.ReadyTimeout <= 0 {
o.ReadyTimeout = DefaultReadyTimeout
}
if o.CleanupTimeout <= 0 {
o.CleanupTimeout = DefaultCleanupTimeout
}
}
func (o *Options) volumes() map[string]struct{} {
volumes := make(map[string]struct{})
for _, v := range o.Volumes {
volumes[v] = struct{}{}
}
return volumes
}
func (o *Options) env() []string {
env := make([]string, 0, len(o.Env))
for k, v := range o.Env {
env = append(env, k+"="+v)
}
return env
}