diff --git a/ntex-util/src/time/mod.rs b/ntex-util/src/time/mod.rs index 8356397a..a33ab6f1 100644 --- a/ntex-util/src/time/mod.rs +++ b/ntex-util/src/time/mod.rs @@ -454,6 +454,13 @@ mod tests { dl.reset(Millis::ZERO); assert!(lazy(|cx| dl.poll_elapsed(cx)).await.is_pending()); + let mut dl = deadline(Millis(1)); + dl.reset(Millis(100)); + let first_time = now(); + dl.await; + let second_time = now(); + assert!(second_time - first_time >= time::Duration::from_millis(100)); + let mut dl = deadline(Millis(0)); assert!(dl.is_elapsed()); dl.reset(Millis(1)); diff --git a/ntex/src/web/middleware/compress.rs b/ntex/src/web/middleware/compress.rs index 0072021f..2bf38126 100644 --- a/ntex/src/web/middleware/compress.rs +++ b/ntex/src/web/middleware/compress.rs @@ -163,3 +163,74 @@ impl AcceptEncoding { ContentEncoding::Identity } } + +#[cfg(test)] +mod tests { + use std::cmp::Ordering; + + use super::*; + + #[test] + fn test_accepting_encodings_equal() { + let accepting_encoding = AcceptEncoding { + encoding: ContentEncoding::Auto, + quality: 0.0, + }; + let accepting_encoding2 = AcceptEncoding { + encoding: ContentEncoding::Br, + quality: 0.0, + }; + + assert!(accepting_encoding == accepting_encoding2); + } + + #[test] + fn test_accepting_encodings_not_equal() { + let accepting_encoding = AcceptEncoding { + encoding: ContentEncoding::Auto, + quality: 1.0, + }; + let accepting_encoding2 = AcceptEncoding { + encoding: ContentEncoding::Br, + quality: 0.0, + }; + + assert!(accepting_encoding != accepting_encoding2); + } + + #[test] + fn test_accepting_encodings_cmp_order_less() { + let accepting_encoding = AcceptEncoding { + encoding: ContentEncoding::Auto, + quality: 1.0, + }; + let accepting_encoding2 = AcceptEncoding { + encoding: ContentEncoding::Br, + quality: 0.0, + }; + + assert_eq!(accepting_encoding.cmp(&accepting_encoding2), Ordering::Less); + } + + #[test] + fn test_accepting_encodings_cmp_order_equal() { + let accepting_encoding = AcceptEncoding { + encoding: ContentEncoding::Auto, + quality: 1.0, + }; + + assert_eq!(accepting_encoding.cmp(&accepting_encoding), Ordering::Equal); + } + + #[test] + fn test_accepting_encoding_from_tag_with_valid_quality() { + let accepting_encoding = AcceptEncoding::new("gzip;0.8").unwrap(); + assert_eq!(accepting_encoding.quality, 0.8); + } + + #[test] + fn test_accepting_encoding_from_tag_with_invalid_quality() { + let accepting_encoding = AcceptEncoding::new("gzip;q=abc").unwrap(); + assert_eq!(accepting_encoding.quality, 0.0); + } +} diff --git a/ntex/src/web/middleware/defaultheaders.rs b/ntex/src/web/middleware/defaultheaders.rs index 2e9d9ae9..54b96605 100644 --- a/ntex/src/web/middleware/defaultheaders.rs +++ b/ntex/src/web/middleware/defaultheaders.rs @@ -175,6 +175,18 @@ mod tests { assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0002"); } + #[crate::rt_test] + #[should_panic(expected = "Cannot create header name")] + async fn test_invalid_header_name() { + DefaultHeaders::new().header("no existing header name", "0001"); + } + + #[crate::rt_test] + #[should_panic(expected = "Cannot create header value")] + async fn test_invalid_header_value() { + DefaultHeaders::new().header(CONTENT_TYPE, "\n"); + } + #[crate::rt_test] async fn test_content_type() { let srv = |req: WebRequest| async move {