Documentation ¶
Overview ¶
test_with_docker provides utilities for using docker-compose for writing integration tests.
Index ¶
- Constants
- func UntilReady(d, max time.Duration, fns ...ReadyFn) error
- type Agent
- type LocalDaemon
- func (ld *LocalDaemon) Cleanup() error
- func (ld *LocalDaemon) ComposeServices(dir string, svcs serviceMap) (*command, error)
- func (ld *LocalDaemon) DifferingFiles(pathPairs ...[]string) (differentPairs [][]string, err error)
- func (ld *LocalDaemon) Exec(args ...string) error
- func (ld *LocalDaemon) IP() (net.IP, error)
- func (ld *LocalDaemon) InstallFile(src string, dest string) error
- func (ld *LocalDaemon) MD5s(paths ...string) (map[string]string, error)
- func (ld *LocalDaemon) RebuildService(dir, name string) error
- func (ld *LocalDaemon) RestartDaemon() error
- func (ld *LocalDaemon) Shutdown(c *command)
- type Machine
- func (m *Machine) Cleanup() error
- func (m *Machine) ComposeServices(dir string, servicePorts serviceMap) (shutdown *command, err error)
- func (m *Machine) DifferingFiles(pathPairs ...[]string) (differentPairs [][]string, err error)
- func (m *Machine) Exec(args ...string) error
- func (m *Machine) IP() (ip net.IP, err error)
- func (m *Machine) InstallFile(sourcePath, destPath string) error
- func (m *Machine) MD5s(paths ...string) (md5s map[string]string, err error)
- func (m *Machine) RebuildService(dir, name string) error
- func (m *Machine) RestartDaemon() error
- func (m *Machine) Shutdown(c *command)
- type ReadyError
- type ReadyFn
Constants ¶
const ( // DefaultTimeout is the default timeout for docker operations. DefaultTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Agent ¶
type Agent interface { // ComposeServices uses docker-compose to set up one or more services, using // serviceMap to check availability. // // Importantly, the serviceMap is used both to determine if the services are // already available - since docker-compose can take some time to execute, it // can be handy to run the compose in a different console and let // ComposeServices discover the services. // // Finally, if ComposeServices determined that a service was missing and // needed to be run, it will return a value that represents the // docker-compose command that it executed. You can pass this value to // Shutdown to shut down the docker-compose after tests have run. ComposeServices(string, serviceMap) (*command, error) // InstallFile puts a path found on the local machine to a path on the docker host. InstallFile(string, string) error // DifferingFile takes a list of pairs of [local, remote] paths, and filters them // for pairs whose contents differ. DifferingFiles(...[]string) ([][]string, error) // IP returns the IP address where the daemon is located. // In order to access the services provided by a docker-compose on a // docker-machine, we need to know the ip address. Some client test code // needs to know the IP address prior to starting up the services, which is // why this function is exposed IP() (net.IP, error) // MD5s computes digests of a list of paths // This can be used to compare to local digests and avoid copying files or // restarting the daemon MD5s(...string) (map[string]string, error) // RebuildService forces the rebuild of a docker-compose service. RebuildService(string, string) error // Shutdown terminates the set of services started by ComposeServices // If passed a nil (as ComposeServices returns in the event that all services // were available, Shutdown is a no-op Shutdown(*command) // RestartDaemon reboots the docker daemon RestartDaemon() error // Exec executes commands as root on the daemon host // It uses sudo Exec(...string) error // Cleanup performs the tasks required to shut down after a test Cleanup() error }
An Agent manages operations directed at Docker This is an interface that abstracts the differece between local docker-daemons (useful, for instance, for Linux based CI (e.g. Travis)) and VM hosted docker-machine managed daemons (e.g. for OS X development.
type LocalDaemon ¶
type LocalDaemon struct {
// contains filtered or unexported fields
}
func (*LocalDaemon) Cleanup ¶
func (ld *LocalDaemon) Cleanup() error
func (*LocalDaemon) ComposeServices ¶
func (ld *LocalDaemon) ComposeServices(dir string, svcs serviceMap) (*command, error)
func (*LocalDaemon) DifferingFiles ¶
func (ld *LocalDaemon) DifferingFiles(pathPairs ...[]string) (differentPairs [][]string, err error)
DifferingFiles compares specific files involved in docker
func (*LocalDaemon) Exec ¶
func (ld *LocalDaemon) Exec(args ...string) error
Exec executes commands as root on the daemon host It uses sudo
func (*LocalDaemon) IP ¶
func (ld *LocalDaemon) IP() (net.IP, error)
IP returns the IP address where the daemon is located. In order to access the services provided by a docker-compose on a docker-machine, we need to know the ip address. Some client test code needs to know the IP address prior to starting up the services, which is why this function is exposed
func (*LocalDaemon) InstallFile ¶
func (ld *LocalDaemon) InstallFile(src string, dest string) error
InstallFile puts a path found on the local machine to a path on the docker host.
func (*LocalDaemon) MD5s ¶
func (ld *LocalDaemon) MD5s(paths ...string) (map[string]string, error)
MD5s computes digests of a list of paths This can be used to compare to local digests and avoid copying files or restarting the daemon
func (*LocalDaemon) RebuildService ¶
func (ld *LocalDaemon) RebuildService(dir, name string) error
RebuildService forces the rebuild of a docker-compose service.
func (*LocalDaemon) RestartDaemon ¶
func (ld *LocalDaemon) RestartDaemon() error
RestartDaemon reboots the docker daemon
func (*LocalDaemon) Shutdown ¶
func (ld *LocalDaemon) Shutdown(c *command)
Shutdown terminates the set of services started by ComposeServices If passed a nil (as ComposeServices returns in the event that all services were available, Shutdown is a no-op
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
func (*Machine) ComposeServices ¶
func (*Machine) DifferingFiles ¶
func (*Machine) Exec ¶
Exec is your out for anything that test_with_docker doesn't provide. It executes `docker-machine ssh <machineName> sudo <args...>` so that you can manipulate the running docker machine
func (*Machine) InstallFile ¶
InstallFile installs a file into the docker-machine
func (*Machine) RebuildService ¶
func (*Machine) RestartDaemon ¶
RestartDaemon restarts the docker daemon on the docker machine VM
func (*Machine) Shutdown ¶
func (m *Machine) Shutdown(c *command)
Shutdown receives a command as produced by ComposeServices is shuts down services launched for testing. If passed a nil command, it functions as a no-op. This means that you can do things like:
ip, cmd, err := ComposeServices(...) defer Shutdown(cmd)
type ReadyError ¶
type ReadyError struct { Errs []error // contains filtered or unexported fields }
A ReadyError is returned when UntilReady doesn't get a universal ready result
func (*ReadyError) Error ¶
func (re *ReadyError) Error() string