Documentation ¶
Index ¶
- Constants
- func API() *client.Client
- func ExecuteWithRunningContainer(t *testing.T, c *Container, userTestFn ContainerTestFn)
- func FromDockerHub(image string, version string) string
- func PullImage(img string, version string, getRepoFn ImageRefFn)
- type Container
- func (c *Container) AddAllEnv(aMap map[string]string)
- func (c *Container) AddEnv(key, value string)
- func (c *Container) AddExposedPort(port ContainerPort)
- func (c *Container) AddPathMap(Host HostPath, Container ContainerPath)
- func (c *Container) AddPortMap(host HostPort, container ContainerPort)
- func (c *Container) AwaitExit(timeoutSeconds int) (ok bool, err error)
- func (c *Container) AwaitIsReady() (started bool, err error)
- func (c *Container) AwaitIsRunning() (started bool, err error)
- func (c *Container) AwaitLogPattern(timeoutSeconds int, patternRegex string) (started bool, err error)
- func (c *Container) Check(timeoutSeconds int) (ret bool, err error)
- func (c *Container) ConnectTCP(timeoutSeconds int) (net.Conn, error)
- func (c *Container) ContainerName() string
- func (c *Container) HostPort() string
- func (c *Container) IPAddress() (string, error)
- func (c *Container) InspectIPAddress() (string, error)
- func (c *Container) IsExited() (started bool, err error)
- func (c *Container) IsRemoveAfterTest() bool
- func (c *Container) IsRunning() (started bool, err error)
- func (c *Container) IsStopAfterTest() bool
- func (c *Container) Logs() (string, error)
- func (c *Container) LogsMatch(pattern string) func() (bool, error)
- func (c *Container) MapToRandomHostPort(containerPort ContainerPort)
- func (c *Container) Port() ContainerPort
- func (c *Container) Remove() error
- func (c *Container) RunCmd(cmd []string) (io.Reader, error)
- func (c *Container) SetAppPort(port string) *Container
- func (c *Container) SetName(name string)
- func (c *Container) SetPort(port string, mappedHostPort string) *Container
- func (c *Container) Start() (string, error)
- func (c *Container) Stop(timeoutSeconds int) (ok bool, err error)
- func (c *Container) WithImage(image string) *Container
- type ContainerConfigFn
- type ContainerGroup
- type ContainerPath
- type ContainerPort
- type ContainerReadyFn
- type ContainerTestFn
- type DBConnectFn
- type GroupedContainer
- type HostPath
- type HostPort
- type ImageRefFn
- type PortMap
- type PropertyMap
- type TCPConnectFn
- type VolumeMount
Constants ¶
const NOPORT = HostPort("")
NOPORT constant for no port specified
Variables ¶
This section is empty.
Functions ¶
func ExecuteWithRunningContainer ¶
func ExecuteWithRunningContainer(t *testing.T, c *Container, userTestFn ContainerTestFn)
ExecuteWithRunningContainer wraps a test function by creating a db
func FromDockerHub ¶
FromDockerHub is the default formatter for a docker image resource provide your own for private repos
func PullImage ¶
func PullImage(img string, version string, getRepoFn ImageRefFn)
PullImage like docker pull cmd
Types ¶
type Container ¶
type Container struct { // Props are metadata for a container type. eg dbusername for a db container // They are not passed directly to the container environment Props PropertyMap // These two are used to create the new container using the Docker API Config *container.Config HostConfig *container.HostConfig // Instance Once the container is started this has all the instance data Instance container.CreateResponse // GetImageRepoSource Overload this if you want to get images from a different repo GetImageRepoSource ImageRefFn `json:"-,"` // will stop and remove the container after testing StopAfterTest bool // RemoveAfterTest remove the container after the test RemoveAfterTest bool // // The docker image to use for the container // dockerImage string // The Maximum time to wait for the container MaxStartTimeSeconds int // NamePrefix is combined with a random suffix to create the containerName // if the name is blank when the container is started NamePrefix string // ContainerReady Override this if you want to check more than an ok response to a TCP connect ContainerReady ContainerReadyFn // TCPConnect fn to connect to a TCP connection TCPConnect TCPConnectFn // DBConnect fn to connect to a DB connection DBConnect DBConnectFn // contains filtered or unexported fields }
Container a simplified API over the docker client API
func ContainerWith ¶
func ContainerWith(fn ContainerConfigFn) *Container
ContainerWith contstructor which takes a custom configurer
func FindContainer ¶ added in v1.2.5
func (*Container) AddExposedPort ¶
func (c *Container) AddExposedPort(port ContainerPort)
AddExposedPort expose a container port
func (*Container) AddPathMap ¶
func (c *Container) AddPathMap(Host HostPath, Container ContainerPath)
AddPathMap like -v cmd switch for mapping paths
func (*Container) AddPortMap ¶
func (c *Container) AddPortMap(host HostPort, container ContainerPort)
AddPortMap like -p cmd line switch for adding port mappings
func (*Container) AwaitIsReady ¶
AwaitIsReady waits for the container is in the running state
func (*Container) AwaitIsRunning ¶
AwaitIsRunning waits for the container is in the running state
func (*Container) AwaitLogPattern ¶
func (c *Container) AwaitLogPattern(timeoutSeconds int, patternRegex string) (started bool, err error)
AwaitLogPattern waits for the container to start based on expected log message patterns
func (*Container) ConnectTCP ¶
ConnectTCP Connects tot he container port using a TCP connection
func (*Container) ContainerName ¶
ContainerName returns the generated name for the container
func (*Container) InspectIPAddress ¶
InspectIPAddress uses docker inspect to find out the ip address
func (*Container) IsRemoveAfterTest ¶
IsRemoveAfterTest true if the container should be removed
func (*Container) IsRunning ¶
IsRunning returns true if the container is in the started state Will error if the container has already exited
func (*Container) IsStopAfterTest ¶
IsStopAfterTest if true then stop the container after the test
func (*Container) MapToRandomHostPort ¶
func (c *Container) MapToRandomHostPort(containerPort ContainerPort)
MapToRandomHostPort like --ports cmd switch for mapping ports
func (*Container) SetAppPort ¶
SetAppPort sets the main port for the container if it has one
func (*Container) SetPort ¶
SetPort sets the main port to be used by the container Other port mappings can be added but this one is considered the big kahuna for checking readiness for example
type ContainerConfigFn ¶
ContainerConfigFn custom function that configures a container
type ContainerGroup ¶
type ContainerGroup map[string]*GroupedContainer
ContainerGroup manages a group of connected containers like docker-compose but in code
func (ContainerGroup) Add ¶
func (cg ContainerGroup) Add(cnt *GroupedContainer)
Add adds a container to the group keyed by its name
func (ContainerGroup) Await ¶
func (cg ContainerGroup) Await()
Await blocks until all containers have started
type ContainerPort ¶
type ContainerPort string
ContainerPort typesafe string subtype
func (ContainerPort) Nat ¶
func (p ContainerPort) Nat() nat.Port
Nat does the string formatting for a nat port
type ContainerReadyFn ¶
ContainerReadyFn should return true when the container is ready to be used
type ContainerTestFn ¶
ContainerTestFn implement your DB tests using this signature
type DBConnectFn ¶
DBConnectFn override this to provide a DB connect function
type GroupedContainer ¶
type GroupedContainer struct { Container *Container // contains filtered or unexported fields }
GroupedContainer container object tracks containers on which this depends
func NewGroupedContainer ¶
func NewGroupedContainer(withContainer *Container) *GroupedContainer
NewGroupedContainer constructor with a container
func (*GroupedContainer) Await ¶
func (gc *GroupedContainer) Await()
Await uses a for range on a channel to wait for all dependent containers to start
func (*GroupedContainer) DependsOn ¶
func (gc *GroupedContainer) DependsOn(containers ...*GroupedContainer)
DependsOn is called to ensure this container wont start until these ones have
func (*GroupedContainer) SignalStarted ¶
func (gc *GroupedContainer) SignalStarted()
SignalStarted signals
func (*GroupedContainer) Start ¶
func (gc *GroupedContainer) Start()
Start starts a container once all the dependents start
type HostPort ¶
type HostPort string
HostPort typesafe string subtype
func (HostPort) Binding ¶
func (p HostPort) Binding() nat.PortBinding
Binding Returns a host binding and optionally creates a random one if none provided
type ImageRefFn ¶
ImageRefFn This function type provides a hook to generate a custom docker repo path if needed You only need this if you're not using the standard docker registry
type PortMap ¶
type PortMap struct { Host HostPort Container ContainerPort }
PortMap defines a host to container port mapping
type PropertyMap ¶
PropertyMap Custom container properties used to configure containers They are stored here for later reference eg by tests eg They could include db username/password for a db type container
func (PropertyMap) GetOrDefault ¶
func (p PropertyMap) GetOrDefault(key string, defaultValue string) string
GetOrDefault returns the specified key value or a default
func (PropertyMap) SetAll ¶
func (p PropertyMap) SetAll(amap PropertyMap)
SetAll sets all the props on the provided map
func (PropertyMap) SetIfMissing ¶
func (p PropertyMap) SetIfMissing(key string, value string)
SetIfMissing sets the value if it isn't already
type TCPConnectFn ¶
TCPConnectFn override this to provide a tcp connect function
type VolumeMount ¶
type VolumeMount struct { Host HostPath Container ContainerPath }
VolumeMount creates a Volume mount from host to container
func (*VolumeMount) Mount ¶
func (v *VolumeMount) Mount() mount.Mount
Mount is a converter to a docker api mount struct