dockertest-rs

Control docker containers from a rust ingegration test suite. Full fledge management support with automatic cleanup.

This crate provides the following features for your docker testing needs:

See the crate documentation for extensive explainations.

Example

The canonical example and motivation for this crate can be expressed with the following use-case example - host a database used by your test in a container, which is fresh between each test.

```rust use diesel::pg::PgConnection; use diesel::prelude::*; use dockertest::waitfor::{MessageSource, MessageWait}; use dockertest::{Composition, DockerTest, PullPolicy, Source}; use std::rc::Rc;

// Define our test let source = Source::DockerHub(PullPolicy::IfNotPresent); let mut test = DockerTest::new().withdefaultsource(source);

// Define our Composition - the Image we will start and end up as our RunningContainer let mut postgres = Composition::withrepository("postgres").withwaitfor(Box::new(MessageWait { message: "database system is ready to accept connections".tostring(), source: MessageSource::Stderr, timeout: 20, })); postgres.env("POSTGRESPASSWORD", "password"); test.addcomposition(postgres);

// Run the test body test.run(|ops| async move { let container = ops.handle("postgres"); let connstring = format!("postgres://postgres:password@{}:{}", container.ip(), 5432); let pgconn = PgConnection::establish(&connstring);

// Perform your database operations here
assert!(
    pgconn.is_ok(),
    "failed to establish connection to postgres docker"
);

}); ```

Testing

Testing this library requires the following: * docker daemon available on localhost. * Capable of compiling diesel with the postgres feature. * Set DOCKERTEST_BUILD_TEST_IMAGES=1 in your environment, will triger the test images to be built.

Tests are designed to be run in parallel, and should not conflict with existing system images. Local images are build with repository prefix dockertest-rs/.