Add test for not hitting debug_assert in MatchedPath (#1935)

This commit is contained in:
David Pedersen 2023-04-17 13:46:54 +02:00 committed by GitHub
parent b42897f2dc
commit 994492d427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -172,11 +172,14 @@ fn append_nested_matched_path(matched_path: &Arc<str>, extensions: &http::Extens
mod tests {
use super::*;
use crate::{
handler::HandlerWithoutStateExt, middleware::map_request, routing::get, test_helpers::*,
body::Body,
handler::HandlerWithoutStateExt,
middleware::map_request,
routing::{any, get},
test_helpers::*,
Router,
};
use http::{Request, StatusCode};
use hyper::Body;
#[crate::test]
async fn extracting_on_handler() {
@ -355,6 +358,26 @@ mod tests {
assert_eq!(res.status(), StatusCode::OK);
}
// https://github.com/tokio-rs/axum/issues/1579
#[crate::test]
async fn doesnt_panic_if_router_called_from_wildcard_route() {
use tower::ServiceExt;
let app = Router::new().route(
"/*path",
any(|req: Request<Body>| {
Router::new()
.nest("/", Router::new().route("/foo", get(|| async {})))
.oneshot(req)
}),
);
let client = TestClient::new(app);
let res = client.get("/foo").send().await;
assert_eq!(res.status(), StatusCode::OK);
}
#[crate::test]
async fn cant_extract_in_fallback() {
async fn handler(path: Option<MatchedPath>, req: Request<Body>) {