Expand description
Some helpers to make it simpler to mock Tower services.
A MockService
is a generic [tower::Service
] implementation that allows intercepting
requests, responding to them individually, and checking that there are no requests to be
received (at least during a period of time). The MockService
can be built for proptests or
for normal Rust unit tests.
§Example
use zebra_test::mock_service::MockService;
let mut mock_service = MockService::build().for_unit_tests();
let mut service = mock_service.clone();
let call = tokio::spawn(mock_service.clone().oneshot("hello"));
mock_service
.expect_request("hello").await
.respond("hi!");
mock_service.expect_no_requests().await;
let response = call
.await
.expect("Failed to run call on the background")
.expect("Failed to receive response from service");
assert_eq!(response, "hi!");
Structs§
- Mock
Service - A service implementation that allows intercepting requests for checking them.
- Mock
Service Builder - A builder type to create a
MockService
. - Response
Sender - A helper type for responding to incoming requests.
Enums§
- Panic
Assertion - Represents normal Rust assertions that panic, like
assert_eq
. - Prop
Test Assertion - Represents [
mod@proptest
] assertions that return errors, likeprop_assert_eq
.
Constants§
- DEFAULT_
MAX_ REQUEST_ DELAY - The default timeout before considering a request has not been received.
- DEFAULT_
PROXY_ 🔒CHANNEL_ SIZE - The default size of the channel that forwards received requests.
Traits§
- Assertion
Type 🔒 - A representation of an assertion type.
- Response
Result - A helper trait to improve ergonomics when sending a response.
Type Aliases§
- Proxy
Item 🔒 - An internal type representing the item that’s sent in the [
broadcast
] channel.