Documentation ¶
Overview ¶
Package dockertest contains helper functions for setting up and tearing down docker containers to aid in testing. dockertest supports spinning up MySQL, PostgreSQL and MongoDB out of the box.
Dockertest provides two environment variables
Index ¶
- Constants
- Variables
- func AwaitReachable(addr string, maxWait time.Duration) error
- func IP(containerID string) (string, error)
- func KillContainer(container string) error
- func Pull(image string) error
- type ContainerID
- func SetupContainer(image string, containerPort int, args ...string) (c ContainerID, ip string, port int, err error)
- func SetupContainerWithEnv(image string, containerPort int, env string, args ...string) (c ContainerID, ip string, port int, err error)
- func SetupElasticSearchContainer() (c ContainerID, ip string, port int, err error)
- func SetupFluentdContainer() (c ContainerID, ip string, port int, err error)
- func SetupMongoContainer(args ...string) (c ContainerID, ip string, port int, err error)
- func SetupMySQLContainer(args ...string) (c ContainerID, ip string, port int, err error)
- func SetupNatsContainer() (c ContainerID, ip string, port int, err error)
- func SetupPostgreSQLContainer(args ...string) (c ContainerID, ip string, port int, err error)
- func SetupRedisContainer() (c ContainerID, ip string, port int, err error)
Constants ¶
const ( // MySQLUsername must be passed as username when connecting to mysql MySQLUsername = "root" // MySQLPassword must be passed as password when connecting to mysql MySQLPassword = "root" // PostgresUsername must be passed as username when connecting to postgres PostgresUsername = "postgres" // PostgresPassword must be passed as password when connecting to postgres PostgresPassword = "docker" )
Variables ¶
var ( // Debug if set, prevents any container from being removed. Debug bool // DockerMachineAvailable if true, uses docker-machine to run docker commands (for running tests on Windows and Mac OS) DockerMachineAvailable bool // DockerMachineName is the machine's name. You might want to use a dedicated machine for running your tests. // You can set this variable either directly or by defining a DOCKERTEST_IMAGE_NAME env variable. DockerMachineName = env.Getenv("DOCKERTEST_IMAGE_NAME", "default") // BindDockerToLocalhost if set, forces docker to bind the image to localhost. This for example is required when running tests on travis-ci. // You can set this variable either directly or by defining a DOCKERTEST_BIND_LOCALHOST env variable. // FIXME DOCKER_BIND_LOCALHOST remove legacy support BindDockerToLocalhost = env.Getenv("DOCKERTEST_BIND_LOCALHOST", env.Getenv("DOCKER_BIND_LOCALHOST", "")) )
Functions ¶
func AwaitReachable ¶
AwaitReachable tries to make a TCP connection to addr regularly. It returns an error if it's unable to make a connection before maxWait.
func KillContainer ¶
KillContainer runs docker kill on a container.
Types ¶
type ContainerID ¶
type ContainerID string
ContainerID represents a container and offers methods like Kill or IP.
func SetupContainer ¶
func SetupContainer(image string, containerPort int, args ...string) (c ContainerID, ip string, port int, err error)
SetupContainer runs docker instance and returns port.
func SetupContainerWithEnv ¶
func SetupContainerWithEnv(image string, containerPort int, env string, args ...string) (c ContainerID, ip string, port int, err error)
SetupContainerWithEnv runs docker instance with env variable and returns port.
func SetupElasticSearchContainer ¶
func SetupElasticSearchContainer() (c ContainerID, ip string, port int, err error)
SetupElasticSearchContainer sets up a real ElasticSearch instance for testing purposes using a Docker container. It returns the container ID and its IP address, or makes the test fail on error.
func SetupFluentdContainer ¶
func SetupFluentdContainer() (c ContainerID, ip string, port int, err error)
SetupFluentdContainer sets up a real natsd instance for testing purposes using Docker container.
func SetupMongoContainer ¶
func SetupMongoContainer(args ...string) (c ContainerID, ip string, port int, err error)
SetupMongoContainer sets up a real MongoDB instance for testing purposes, using a Docker container. It returns the container ID and its IP address, or makes the test fail on error.
func SetupMySQLContainer ¶
func SetupMySQLContainer(args ...string) (c ContainerID, ip string, port int, err error)
SetupMySQLContainer sets up a real MySQL instance for testing purposes, using a Docker container. It returns the container ID and its IP address, or makes the test fail on error.
func SetupNatsContainer ¶
func SetupNatsContainer() (c ContainerID, ip string, port int, err error)
SetupNatsContainer sets up a real natsd instance for testing purposes using Docker container.
func SetupPostgreSQLContainer ¶
func SetupPostgreSQLContainer(args ...string) (c ContainerID, ip string, port int, err error)
SetupPostgreSQLContainer sets up a real PostgreSQL instance for testing purposes, using a Docker container. It returns the container ID and its IP address, or makes the test fail on error.
func SetupRedisContainer ¶
func SetupRedisContainer() (c ContainerID, ip string, port int, err error)
SetupRedisContainer sets up a real Redis instance for testing purposes using a Docker container. It returns the container ID and its IP address, or makes the test fail on error.
func (ContainerID) IP ¶
func (c ContainerID) IP() (string, error)
IP retrieves the container's IP address.
func (ContainerID) Kill ¶
func (c ContainerID) Kill() error
Kill runs "docker kill" on the container.
func (ContainerID) KillRemove ¶
func (c ContainerID) KillRemove() error
KillRemove calls Kill on the container, and then Remove if there was no error.
func (ContainerID) Remove ¶
func (c ContainerID) Remove() error
Remove runs "docker rm" on the container