Module preroll::test_utils [−][src]
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_eq!(body, "preroll_test_utils"); Ok(()) }
Functions
assert_json_error | A test helper to check all fields of a |
assert_status | Assert that a response has a specified status code and return the body as a string. |
assert_status_json | Assert that a response has a status code and parse out the body to JSON if possible. |
create_client | Creates a test application with routes and mocks set up, and hands back a client which is already connected to the server. |
create_client_and_postgres | postgres Creates a test application with routes and mocks set up, and hands back a client which is already connected to the server. |
mock_client | Creates a mock client directly connected to a server which is setup by the provided function. |
Type Definitions
TestResult | The result type to use for tests. |