Expand description
This crate is to be used to test tower_async_layer::Layers,
by helping you write tests to guarantee this.
The guarantees that it test are:
- the
tower_async_service::Servicewrapped by thetower_async_layer::Layerreceives the expected requests, and that your layer react as expected on the sent responses or errors. - the
tower_async_layer::Layersends back the expected response or error.
It does so by providing a crate::Builder that you can use to define the
test flow and expectations. It does this by a generated crate::mock::Mock tower_async_service::Service
that is used as the core tower_async_service::Service to help you
test your own tower_async_layer::Layers with the crate::mock::Mock tower_async_service::Service.
The crate::mock::Mock service cannot be used directly, but is instead use
automatically for any test spawned using the crate::Builder and specifically
its crate::Builder::test method.
§Examples
use tower_async_test::Builder;
use tower_async_layer::Identity;
#[tokio::main]
async fn main() {
Builder::new("ping")
.send_response("pong")
.expect_request("ping")
.test(Identity::new())
.await
.expect_response("pong");
}Re-exports§
pub use builder::Builder;
Modules§
- builder
- Builder for creating
crate::mock::Mockservices and testing them with atower_async_layer::Layer. - mock
- This module provides the
Mocktower_async_service::Servicethat is used by this crate as the coretower_async_service::Serviceto help you test your owntower_async_layer::Layers.