Skip to content

Commit

Permalink
test(request): validate send_request works (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Dec 28, 2023
1 parent 7518582 commit 6c5f550
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions hitt-request/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,37 @@ pub async fn send_request(
body: res.text().await.unwrap_or_default(),
})
}

#[cfg(test)]
mod test_send_request {
use core::str::FromStr;

use http::{HeaderMap, StatusCode};

use crate::send_request;

#[tokio::test]
async fn it_should_return_a_response() {
let http_client = reqwest::Client::new();

let timeout = None;

let uri = http::Uri::from_str("https://dummyjson.com/products/1").unwrap();

let input = hitt_parser::HittRequest {
method: http::Method::GET,
uri: uri.clone(),
headers: HeaderMap::default(),
body: None,
http_version: None,
};

let result = send_request(&http_client, &input, &timeout)
.await
.expect("it to be successfull");

assert_eq!(result.url, uri.to_string());

assert_eq!(result.status_code, StatusCode::OK);
}
}

0 comments on commit 6c5f550

Please sign in to comment.