dockertest-rs
Run docker containers in your Rust integration tests.
This crate provides the following features for your docker testing needs:
- Ensure one or more docker containers are running before your test executes.
- Teardown each started container after test is terminated (both successfully and on test failure).
- Control origin and management of
Image
s used for your docker containers and the pull policy thereof. Supported sources are:- Local - must be present on the host machine.
- DockerHub - fetch from the offical DockerHub.
- Custom - custom docker registry. (Currently not implemented)
Architecture
This shows the various stages of components in dockertest-rs.
Image -> Composition -> PendingContainer -> RunningContainer
An Image
represents a built image from docker that we may attempt to start a container of.
A Composition
is a specific instance of an Image
, with its runtime parameters supplied.
The PendingContainer
represents a docker container who is either built or running,
but not yet in the control of the test body.
Once the test body executes, all containers will be available as RunningContainer
s and
all operations present on this object will be available to the test body.
Example
use PgConnection;
use *;
use ;
use ;
let source = DockerHub;
let mut test = new.with_default_source;
let repo = "postgres";
let postgres = with_repository;
test.add_composition;
test.run;
Development
This library is in its initial inception. Breaking changes are to be expected.
Testing
Testing this library requires the following:
- docker daemon available on localhost.
- Capable of compiling
diesel
with the postgres feature.
Run the tests with the following command:
cargo test -- --test-threads=1
Caveats that may fail tests:
- Port
5432
is already taken for postgres on the host. - Exited
hello-world
containers on the system. This will currently make removing old images fail and many tests will fail. This is an area we need to improve.
TODO:
- Document limits when spawning stuff in test body.
- Document handle concept.
- Break up Container into PendingContainer and RunningContainer.
- Document and implement port mapping for random host port assignment.