Documentation ¶
Overview ¶
Package testingdock simplifies integration testing with docker.
Note: this library spawns containers and networks under the label 'owner=testingdock', which may be subject to aggressive manipulation and cleanup.
Testingdock also makes use of the 'flag' package to set global variables. Run `flag.Parse()` in your test suite main function. Possible flags are:
-testingdock.sequential (spawn containers sequentially instead of parallel) -testingdock.verbose (verbose logging)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SpawnSequential bool
SpawnSequential controls whether to spawn child containers in parallel or sequentially. This doesn't spawn all containers in parallel, only the ones that are on the same hierarchy level, e.g.:
// c1 and c2 are started in parallel after the network network.After(c1) network.After(c2) // c3 and c4 are started in parallel after c1 c1.After(c3) c1.After(c4)
var Verbose bool
Verbose logging
Functions ¶
func RandomPort ¶
RandomPort returns a random available port as a string.
func UnregisterAll ¶
func UnregisterAll()
UnregisterAll unregisters all suites by closing the networks.
Types ¶
type Container ¶
type Container struct {
ID, Name, Image string
// contains filtered or unexported fields
}
Container is a docker container configuration, not necessarily a running or created container. This should usually be created via the NewContainer function.
type ContainerOpts ¶
type ContainerOpts struct { ForcePull bool // AutoRemove is always set to true Config *container.Config HostConfig *container.HostConfig Name string // Function called on start and reset to check whether the container // is 'really' up, it will block until it returns nil. The zero // value is a function, which just checks the docker container // has started. HealthCheck HealthCheckFunc // default is 30s HealthCheckTimeout time.Duration // Function called when the containers are reset. The zero value is // a function, which will restart the container completely. Reset ResetFunc }
ContainerOpts is an option struct for creating a docker container configuration.
type HealthCheckFunc ¶
HealthCheckFunc is the type of a health checking function, which is supposed to return nil on success, indicating that a container is not only "up", but "accessible" in the specified way.
If the function returns an error, it will be called until it doesn't (blocking).
func HealthCheckCustom ¶
func HealthCheckCustom(fn func() error) HealthCheckFunc
HealthCheckCustom is just a convenience wrapper to set a HealthCheckFunc without any arguments.
func HealthCheckHTTP ¶
func HealthCheckHTTP(url string) HealthCheckFunc
HealthCheckHTTP is a pre-implemented HealthCheckFunc which checks if the given url returns http.StatusOk.
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network is a struct representing a docker network configuration. This should usually not be created directly but via the NewNetwork function or in the Suite.
type NetworkOpts ¶
type NetworkOpts struct {
Name string
}
NetworkOpts is used when creating a new network.
type ResetFunc ¶
ResetFunc is the type of the container reset function, which is called on c.Reset().
func ResetCustom ¶
ResetCustom is just a convenience wrapper to set a ResetFunc.
type Suite ¶
type Suite struct {
// contains filtered or unexported fields
}
Suite represents a testing suite with a docker setup.
func GetOrCreateSuite ¶
GetOrCreateSuite returns a suite with the given name. If such suite is not registered yet it creates it. Returns true if the suite was already there, otherwise false.
func (*Suite) Close ¶
Close stops the suites. This stops all networks in the suite and the underlying containers.
func (*Suite) Container ¶
func (s *Suite) Container(opts ContainerOpts) *Container
Container creates a new docker container configuration with the given options.
func (*Suite) Network ¶
func (s *Suite) Network(opts NetworkOpts) *Network
Network creates a new docker network configuration with the given options.
func (*Suite) Reset ¶
Reset "resets" the underlying docker containers in the network. This calls the ResetFunc and HealthCheckFunc for each of them. These can be passed in ContainerOpts when creating a container.
The context is passed explicitly to ResetFunc, where it can be used and implicitly to HealthCheckFunc where it may cancel the blocking health check loop.