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: TTrait Implementations§
Source§impl<T: Clone> Clone for MockConnectInfo<T>
 
impl<T: Clone> Clone for MockConnectInfo<T>
Source§fn clone(&self) -> MockConnectInfo<T>
 
fn clone(&self) -> MockConnectInfo<T>
Returns a duplicate 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 moreSource§impl<T: Debug> Debug for MockConnectInfo<T>
 
impl<T: Debug> Debug for MockConnectInfo<T>
Source§impl<S, T> Layer<S> for MockConnectInfo<T>
 
impl<S, T> Layer<S> for MockConnectInfo<T>
impl<T: Copy> Copy for MockConnectInfo<T>
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