Struct catalyzer::internals::crates::axum::extract::connect_info::MockConnectInfo
pub struct MockConnectInfo<T>(pub T);
Expand description
Middleware used to mock ConnectInfo
during tests.
If you’re accidentally using MockConnectInfo
and
Router::into_make_service_with_connect_info
at the same time then
Router::into_make_service_with_connect_info
takes precedence.
§Example
use axum::{
Router,
extract::connect_info::{MockConnectInfo, ConnectInfo},
body::Body,
routing::get,
http::{Request, StatusCode},
};
use std::net::SocketAddr;
use tower::ServiceExt;
async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) {}
// this router you can run with `app.into_make_service_with_connect_info::<SocketAddr>()`
fn app() -> Router {
Router::new().route("/", get(handler))
}
// use this router for tests
fn test_app() -> Router {
app().layer(MockConnectInfo(SocketAddr::from(([0, 0, 0, 0], 1337))))
}
// #[tokio::test]
async fn some_test() {
let app = test_app();
let request = Request::new(Body::empty());
let response = app.oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
}
Tuple Fields§
§0: T
Trait Implementations§
§impl<T> Clone for MockConnectInfo<T>where
T: Clone,
impl<T> Clone for MockConnectInfo<T>where
T: Clone,
§fn clone(&self) -> MockConnectInfo<T>
fn clone(&self) -> MockConnectInfo<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more§impl<T> Debug for MockConnectInfo<T>where
T: Debug,
impl<T> Debug for MockConnectInfo<T>where
T: Debug,
§impl<S, T> Layer<S> for MockConnectInfo<T>
impl<S, T> Layer<S> for MockConnectInfo<T>
impl<T> Copy for MockConnectInfo<T>where
T: Copy,
Auto Trait Implementations§
impl<T> Freeze for MockConnectInfo<T>where
T: Freeze,
impl<T> RefUnwindSafe for MockConnectInfo<T>where
T: RefUnwindSafe,
impl<T> Send for MockConnectInfo<T>where
T: Send,
impl<T> Sync for MockConnectInfo<T>where
T: Sync,
impl<T> Unpin for MockConnectInfo<T>where
T: Unpin,
impl<T> UnwindSafe for MockConnectInfo<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more