#test-framework #integration-tests #framework #docker #test-server #suite

dev dockertest-server

A test framework built around dockertest for testing against server containers

8 releases

0.1.7 May 13, 2022
0.1.6 Mar 15, 2022
0.1.5 Nov 19, 2021
0.1.4 Sep 30, 2021

#420 in Testing

Download history 24/week @ 2024-06-16 21/week @ 2024-06-23 64/week @ 2024-06-30 8/week @ 2024-07-07 21/week @ 2024-07-14 13/week @ 2024-07-21 44/week @ 2024-07-28 13/week @ 2024-08-04 15/week @ 2024-08-11 12/week @ 2024-08-18 24/week @ 2024-08-25 16/week @ 2024-09-01 11/week @ 2024-09-08 4/week @ 2024-09-15 31/week @ 2024-09-22 22/week @ 2024-09-29

68 downloads per month
Used in 6 crates

MIT license

60KB
1.5K SLoC

dockertest-server

A test framework built around dockertest for testing against server containers.

This crate provides a small abstraction layer around the dockertest crate for easily running a test against multiple servers running in containers. It provides traits for defining a server and it's associated configuration and then registering a variable number of servers to bring up for a test.

The primary use-case of this crate is to provide an easy-to-use testing framework for crates that wish to build integration tests against services which are able to run in a container.

Installation

Add dockertest-server as a dependency to your cargo.toml:

[dev-dependencies]
dockertest-server = "0.1.7"

Usage

The below example brings up a mock OAuth server and then tests it's responding to HTTP requests:

// Note: This requires the `web` feature
use dockertest_server::servers::auth::{OIDCServer, OIDCServerConfig};
use dockertest_server::Test;

let config = OIDCServerConfig::builder().port(8090).build().unwrap();
let mut test = Test::new();
test.register(config);

test.run(|instance| async move {
    let server: OIDCServer = instance.server();

    let client = reqwest::Client::new();
    let resp = client
        .get(format!(
            "{}/default/.well-known/openid-configuration",
            server.external_url()
        ))
        .send()
        .await;
    assert!(resp.is_ok());
    assert_eq!(resp.unwrap().status(), 200);
});

This crate ships with support for various servers already included. See the servers module for the ones included. Note that most require a feature flag to be enabled to avoid bundling unnecessary implementations.

Please feel free to submit a PR with your own implementations to be added to the main crate.

Testing

Run tests with cargo test.

Contributing

Check out the issues for items needing attention or submit your own and then:

  1. Fork the repo (https://github.com/jmgilman/dockertest-server/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Dependencies

~14–25MB
~406K SLoC