mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 21:07:39 +03:00
test: improve test coverage (#358)
* test(ntex-util): incrase time module coverage * test(middleware): increase coverage in defaultheaders * test(middleware/compress): improve test coverage
This commit is contained in:
parent
55dcad5f27
commit
d8f55decb0
3 changed files with 90 additions and 0 deletions
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DefaultError>| async move {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue