test: improve coverage in client builder and time types (#357)

This commit is contained in:
msga-mmm 2024-05-10 02:25:13 -05:00 committed by GitHub
parent 1b3a530fb7
commit 33c8900172
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 0 deletions

View file

@ -227,9 +227,24 @@ mod tests {
let m = Millis::from(Duration::from_secs(1));
assert_eq!(m.0, 1000);
let m = Millis::from(Duration::from_secs(u64::MAX));
assert_eq!(m.0, 2_147_483_648);
let m = Millis::from_secs(1);
assert_eq!(m.0, 1000);
let m = Millis(0);
assert_eq!(m.map(|m| m + Millis(1)), None);
let m = Millis(1);
assert_eq!(m.map(|m| m + Millis(1)), Some(Millis(2)));
let s = Seconds::new(10);
assert_eq!(s.0, 10);
let s = Seconds::checked_new(10);
assert_eq!(s.0, 10);
let s = Seconds::checked_new(u16::MAX as usize + 10);
assert_eq!(s.0, u16::MAX);
@ -247,5 +262,8 @@ mod tests {
assert_eq!(Seconds(0).map(|_| 1usize), None);
assert_eq!(Seconds(2).map(|_| 1usize), Some(1));
let d = Duration::from(Seconds(100));
assert_eq!(d.as_secs(), 100);
}
}

View file

@ -175,6 +175,52 @@ mod tests {
assert_eq!(builder.max_redirects, 10);
}
#[crate::rt_test]
async fn response_payload_limit() {
let builder = ClientBuilder::default();
assert_eq!(builder.config.response_pl_limit, 262_144);
let builder = builder.response_payload_limit(10);
assert_eq!(builder.config.response_pl_limit, 10);
}
#[crate::rt_test]
async fn response_payload_timeout() {
let builder = ClientBuilder::default();
assert_eq!(builder.config.response_pl_timeout, Millis(10_000));
let builder = builder.response_payload_timeout(Millis(10));
assert_eq!(builder.config.response_pl_timeout, Millis(10));
}
#[crate::rt_test]
async fn valid_header_name() {
let builder = ClientBuilder::new().header("Content-Length", 1);
assert!(builder.config.headers.contains_key("Content-Length"));
}
#[crate::rt_test]
async fn invalid_header_name() {
let builder = ClientBuilder::new().header("no valid header name", 1);
assert!(!builder.config.headers.contains_key("no valid header name"));
}
#[crate::rt_test]
async fn valid_header_value() {
let valid_header_value = HeaderValue::from(1234);
let builder = ClientBuilder::new().header("Content-Length", &valid_header_value);
assert_eq!(
builder.config.headers.get("Content-Length"),
Some(&valid_header_value)
);
}
#[crate::rt_test]
async fn invalid_header_value() {
let builder = ClientBuilder::new().header("Content-Length", "\n");
assert!(!builder.config.headers.contains_key("Content-Length"));
}
#[crate::rt_test]
async fn client_basic_auth() {
let client = ClientBuilder::new().basic_auth("username", Some("password"));