diff --git a/ntex/src/web/error.rs b/ntex/src/web/error.rs index f6eabc47..03bac2a3 100644 --- a/ntex/src/web/error.rs +++ b/ntex/src/web/error.rs @@ -679,6 +679,7 @@ mod tests { use std::io; use super::*; + use crate::http; use crate::http::client::error::{ConnectError, SendRequestError}; use crate::web::test::TestRequest; @@ -712,6 +713,12 @@ mod tests { ); assert_eq!(resp.status(), StatusCode::GATEWAY_TIMEOUT); + let resp = WebResponseError::::error_response( + &TimeoutError::::Service(UrlencodedError::Chunked), + &req, + ); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + let resp = WebResponseError::::error_response( &SendRequestError::Connect(ConnectError::Timeout), &req, @@ -752,6 +759,15 @@ mod tests { let err = PayloadError::Decoding; let resp = WebResponseError::::error_response(&err, &req); assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + + #[allow(invalid_from_utf8)] + let err = std::str::from_utf8(b"\xF0").unwrap_err(); + let resp = WebResponseError::::error_response(&err, &req); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + + let err = http::error::PayloadError::EncodingCorrupted; + let resp = WebResponseError::::error_response(&err, &req); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); } #[test] diff --git a/ntex/src/web/route.rs b/ntex/src/web/route.rs index b44aba7f..a042ea34 100644 --- a/ntex/src/web/route.rs +++ b/ntex/src/web/route.rs @@ -278,6 +278,8 @@ array_routes!(12, a, b, c, d, e, f, g, h, i, j, k, l); #[cfg(test)] mod tests { + use ntex_service::ServiceFactory; + use crate::http::{header, Method, StatusCode}; use crate::time::{sleep, Millis}; use crate::util::Bytes; @@ -372,5 +374,23 @@ mod tests { let body = read_body(resp).await; assert_eq!(body, Bytes::from_static(b"{\"name\":\"test\"}")); + + let route: web::Route = web::get(); + let repr = format!("{:?}", route); + assert!(repr.contains("Route")); + assert!(repr + .contains("handler: Handler(\"ntex::web::route::Route::new::{{closure}}\")")); + assert!(repr.contains("methods: [GET]")); + assert!(repr.contains("guards: AllGuard()")); + + assert!(route.create(()).await.is_ok()); + + let route_service = route.service(); + let repr = format!("{:?}", route_service); + assert!(repr.contains("RouteService")); + assert!(repr + .contains("handler: Handler(\"ntex::web::route::Route::new::{{closure}}\")")); + assert!(repr.contains("methods: [GET]")); + assert!(repr.contains("guards: AllGuard()")); } }