Go PGRunner
PGunner: An easy way to run postgres in unit and integration tests, from Docker.
Every call of PGRunner will create a new, private Postgres instance in the local Docker Engine,
and expose a unique URL that clients can use to connect to it.
Usage
When using pgrunner from docker, you must run it as root and
pass the define the following environment variables:
PGRUNNER_TEMP_DIR
: "/some/writable/path"
PGRUNNER_EXEC_AS_ROOT
: "true"
Mount as volume, on the container, a directory which has the same name as the host directory.
Finally, you must make the docker socket available in the container.
For instance, this is an example of docker command used to run the unit tests inside docker:
docker run -it --rm \
-e PGRUNNER_TEMP_DIR=/tmp/shared \
-e PGRUNNER_EXEC_AS_ROOT=true \
-v /var/run/docker.sock:/var/run/docker.sock:rw \
-v </path/to/pgrunner>:/src:ro \
-v /some/writable/path/:/some/writable/path/:rw \
-w /src \
golang:latest \
go test ./...
Similar projects
The best and most widely used alternative for this package is Dockertest,
although PGRunner has a much narrower scope and simpler codebase, as it aims to only run Postgres, instead of being
a generic way to run docker services from integration tests.
TODO
- Document it
- CI/CD stuff
- Improve API