Skip to content

Commit

Permalink
Add async tests for request matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
lipanski committed Nov 12, 2024
1 parent b6df40d commit bb6a200
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,42 @@ async fn test_match_body_asnyc() {
assert_eq!(200, response.status());
}

#[tokio::test]
async fn test_request_matcher_body_async() {
let mut s = Server::new_async().await;
let m = s
.mock("POST", "/")
.match_request(|req| {
let body = req.utf8_lossy_body().unwrap();
body.contains("hello")
})
.with_body("world")
.create_async()
.await;

let response = reqwest::Client::new()
.post(s.url())
.version(reqwest::Version::HTTP_11)
.body("bye")
.send()
.await
.unwrap();

assert_eq!(501, response.status());

let response = reqwest::Client::new()
.post(s.url())
.version(reqwest::Version::HTTP_11)
.body("hello")
.send()
.await
.unwrap();

assert_eq!(200, response.status());

m.assert_async().await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_join_all_async() {
let _lock = SERIAL_POOL_TESTS.lock().await;
Expand Down

0 comments on commit bb6a200

Please sign in to comment.