Improve tests (#158)

* Improve tests
This commit is contained in:
Nikolay Kim 2023-01-06 22:08:24 +06:00 committed by GitHub
parent 2f68a2a641
commit f47e830cfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 183 additions and 25 deletions

View file

@ -145,6 +145,7 @@ impl From<std::convert::Infallible> for Error {
#[cfg(test)]
mod tests {
use super::*;
use std::error::Error as StdError;
#[test]
fn inner_error_is_invalid_status_code() {
@ -155,8 +156,12 @@ mod tests {
assert!(ie.is::<status::InvalidStatusCode>());
ie.downcast_ref::<status::InvalidStatusCode>().unwrap();
assert!(err.source().is_none());
assert!(!err.is::<InvalidHeaderValue>());
assert!(err.is::<status::InvalidStatusCode>());
let s = format!("{:?}", err);
assert!(s.starts_with("ntex_http::Error"));
} else {
panic!("Bad status allowed!");
}

View file

@ -758,6 +758,9 @@ mod tests {
let hdr2 = HeaderValue::from(&hdr);
assert_eq!(hdr, hdr2);
let hdr3 = HeaderValue::from_maybe_shared(Bytes::from_static(b"upgrade")).unwrap();
assert_eq!(hdr, hdr3);
let hdr = http::header::HeaderValue::from_bytes(b"upgrade").unwrap();
let hdr2 = HeaderValue::from(&hdr);
assert_eq!(hdr2.as_bytes(), b"upgrade");
@ -767,10 +770,29 @@ mod tests {
let hdr = HeaderValue::try_from("upgrade".to_string()).unwrap();
assert_eq!(hdr.as_bytes(), b"upgrade");
let hdr = HeaderValue::try_from(&("upgrade".to_string())).unwrap();
assert_eq!(hdr.as_bytes(), b"upgrade");
let hdr = HeaderValue::try_from(ByteString::from("upgrade")).unwrap();
assert_eq!(hdr.as_bytes(), b"upgrade");
let hdr = HeaderValue::try_from(&ByteString::from("upgrade")).unwrap();
assert_eq!(hdr.as_bytes(), b"upgrade");
let hdr2 = HeaderValue::try_from(&ByteString::from("upgrade2")).unwrap();
assert!(hdr == hdr);
assert!(hdr == &hdr);
assert!(hdr == "upgrade");
assert!(hdr == "upgrade".to_string());
assert!("upgrade" == hdr);
assert!("upgrade" == &hdr);
assert!("upgrade".to_string() == hdr);
assert!(hdr < hdr2);
assert!(hdr < &hdr2);
assert!(&hdr < &hdr2);
assert!(&hdr < "upgrade2");
assert!(hdr < "upgrade2");
assert!(hdr < "upgrade2".to_string());
assert!("upgrade2" > hdr);
assert!("upgrade2".to_string() > hdr);
}
#[test]