diff --git a/axum-extra/src/extract/with_rejection.rs b/axum-extra/src/extract/with_rejection.rs index 586afa5f..0f40fa00 100644 --- a/axum-extra/src/extract/with_rejection.rs +++ b/axum-extra/src/extract/with_rejection.rs @@ -41,3 +41,46 @@ where Ok(WithRejection(extractor, PhantomData)) } } + +#[cfg(test)] +mod tests { + use axum::http::Request; + use axum::response::Response; + + use super::*; + + #[tokio::test] + async fn extractor_rejection_is_transformed() { + struct TestExtractor; + struct TestRejection; + + #[async_trait] + impl FromRequest for TestExtractor { + type Rejection = (); + + async fn from_request(_: &mut RequestParts) -> Result { + Err(()) + } + } + + impl IntoResponse for TestRejection { + fn into_response(self) -> Response { + ().into_response() + } + } + + impl From<()> for TestRejection { + fn from(_: ()) -> Self { + TestRejection + } + } + + let mut req = RequestParts::new(Request::new(())); + + let result = req + .extract::>() + .await; + + assert!(matches!(result, Err(TestRejection))) + } +}