mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-29 00:00:18 +02:00
Refactor TestClient usage (#3121)
This commit is contained in:
@@ -166,3 +166,28 @@ where
|
||||
Ok(req.into_body())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use axum::{extract::Extension, routing::get, test_helpers::*, Router};
|
||||
use http::{Method, StatusCode};
|
||||
|
||||
#[crate::test]
|
||||
async fn extract_request_parts() {
|
||||
#[derive(Clone)]
|
||||
struct Ext;
|
||||
|
||||
async fn handler(parts: http::request::Parts) {
|
||||
assert_eq!(parts.method, Method::GET);
|
||||
assert_eq!(parts.uri, "/");
|
||||
assert_eq!(parts.version, http::Version::HTTP_11);
|
||||
assert_eq!(parts.headers["x-foo"], "123");
|
||||
parts.extensions.get::<Ext>().unwrap();
|
||||
}
|
||||
|
||||
let client = TestClient::new(Router::new().route("/", get(handler)).layer(Extension(Ext)));
|
||||
|
||||
let res = client.get("/").header("x-foo", "123").await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user