dockertest_server/
lib.rs

1//! # dockertest-server
2//!
3//! > A test framework built around [dockertest][1] for testing against server containers.
4//!
5//! This crate provides a small abstraction layer around the
6//! [dockertest][1] crate for easily running a test against multiple servers running
7//! in containers. It provides traits for defining a server and it's associated
8//! configuration and then registering a variable number of servers to bring up for
9//! a test.
10//!
11//! The primary use-case of this crate is to provide an easy-to-use testing
12//! framework for crates that wish to build integration tests against services which
13//! are able to run in a container.
14//!
15//! ## Installation
16//!
17//! Add `dockertest-server` as a dependency to your cargo.toml:
18//! ```ignore
19//! [dev-dependencies]
20//! dockertest-server = "0.1.7"
21//! ```
22//!
23//! ## Usage
24//!
25//! The below example brings up a mock OAuth server and then tests it's responding
26//! to HTTP requests:
27//!
28//! ```rust
29//! // Note: This requires the `web` feature
30//! use dockertest_server::servers::auth::{OIDCServer, OIDCServerConfig};
31//! use dockertest_server::Test;
32//!
33//! let config = OIDCServerConfig::builder().port(8090).build().unwrap();
34//! let mut test = Test::new();
35//! test.register(config);
36//!
37//! test.run(|instance| async move {
38//!     let server: OIDCServer = instance.server();
39//!
40//!     let client = reqwest::Client::new();
41//!     let resp = client
42//!         .get(format!(
43//!             "{}/default/.well-known/openid-configuration",
44//!             server.external_url()
45//!         ))
46//!         .send()
47//!         .await;
48//!     assert!(resp.is_ok());
49//!     assert_eq!(resp.unwrap().status(), 200);
50//! });
51//! ```
52//!
53//! This crate ships with support for various servers already included. See the
54//! `servers` module for the ones included. Note that most require a feature flag to
55//! be enabled to avoid bundling unnecessary implementations.
56//!
57//! Please feel free to submit a PR with your own implementations to be added to the
58//! main crate.
59//!
60//! ## Testing
61//!
62//! Run tests with `cargo test`.
63//!
64//! [1]: https://crates.io/crates/dockertest
65
66pub mod common;
67pub mod server;
68pub mod servers;
69pub mod test;
70
71pub use server::{new_handle, Config, ContainerConfig, Server};
72pub use test::{Test, TestInstance};