Module preroll::test_utils
source · [−]Expand description
Utilities for setting up mock clients and test servers with similar features to preroll::main!
.
See preroll-example on GitHub for a full example of how to integrate test_utils for a service.
Example:
use preroll::test_utils::{self, assert_status, TestResult};
pub fn setup_routes(mut server: tide::Route<'_, std::sync::Arc<()>>) {
// Normally imported from your service's crate (lib.rs).
}
#[async_std::main] // Would be #[async_std::test] instead.
async fn main() -> TestResult<()> {
let client = test_utils::create_client((), setup_routes).await.unwrap();
let mut res = client.get("/monitor/ping").await.unwrap();
let body = assert_status(&mut res, 200).await;
assert!(!body.is_empty());
Ok(())
}
Functions
A test helper to check all fields of a JsonError
.
Assert that a response has a specified status code and return the body as a string.
Assert that a response has a status code and parse out the body to JSON if possible.
Creates a test application with routes and mocks set up, and hands back a client which is already connected to the server.
postgres
Creates a test application with routes and mocks set up, and hands back a client which is already connected to the server.
Creates a mock client directly connected to a server which is setup by the provided function.
Type Definitions
The result type to use for tests.