Function preroll::test_utils::mock_client
source · [−]pub fn mock_client<MocksFn>(
base_url: impl AsRef<str>,
setup_mocks_fn: MocksFn
) -> Client where
MocksFn: Fn(&mut Server<()>),
Expand description
Creates a mock client directly connected to a server which is setup by the provided function.
Example:
use preroll::test_utils;
use tide::Server;
fn setup_example_local_org_mocks(mock: &mut Server<()>) {
mock.at("hello-world").get(|_| async { Ok("Hello World!") });
}
#[async_std::main]
async fn main() {
let client = test_utils::mock_client("http://api.example_local.org/", setup_example_local_org_mocks);
let response = client
.get("http://api.example_local.org/hello-world")
.recv_string()
.await
.unwrap();
assert_eq!(response, "Hello World!");
}