Compox (compox v0.1.1)

Module to work with a Docker environment for testing.

Compox starts Docker containers when the application starts (see configuration for more info).

Containers availability

Compox makes two checks to ensure the containers are available:

  • the container has running status.
  • the exposed ports to the host, if any, accept connections.

Configuration

  • auto_start: Whether the docker compose services should start with this application. Defaults to true.

  • auto_stop: Whether the docker compose services should stop after the tests. Defaults to true.

  • exclude: The list of Docker services to exclude. These services won't be started by Compox.

  • container_upchecks: Keyword list of functions that will be used to check if a container an up state. See Compox.Docker.Containers documentation for more info.

  • kill_on_finish: Kills the containers instead of stopping them.

Container upchecks

There are containers that need more checks rather than just accepting connection on a port. In those cases, you can use container_upchecks config and provide a function that will be reevaluated until it returns :ok.

Example: checking Postgres connection

If you use a PostgreSQL containers, you will need to ensure that ecto will be able to connect to the container before running the tests. In the following example, we will be using Postgrex.Protocol.connect/1 to attempt a connection to the database. The upcheck function will check whether the Postgres connection returned an application (invalid credentials, unknown catalog...) or a connection error.

Summary

Functions

Returns a specification to start this module under a supervisor.

Stops all the started containers.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

stop()

@spec stop() :: :ok

Stops all the started containers.

Any container started using the docker-compose.yml will be stopped.