package container import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/strslice" "github.com/docker/go-connections/nat" ) // WithName sets the name of the container func WithName(name string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.Name = name } } // WithLinks sets the links of the container func WithLinks(links ...string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.HostConfig.Links = links } } // WithCmd sets the comannds of the container func WithCmd(cmds ...string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.Config.Cmd = strslice.StrSlice(cmds) } } // WithNetworkMode sets the network mode of the container func WithNetworkMode(mode string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.HostConfig.NetworkMode = containertypes.NetworkMode(mode) } } // WithExposedPorts sets the exposed ports of the container func WithExposedPorts(ports ...string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.Config.ExposedPorts = map[nat.Port]struct{}{} for _, port := range ports { c.Config.ExposedPorts[nat.Port(port)] = struct{}{} } } } // WithTty sets the TTY mode of the container func WithTty(tty bool) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.Config.Tty = tty } } // WithWorkingDir sets the working dir of the container func WithWorkingDir(dir string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.Config.WorkingDir = dir } }