Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Johnson <alex.kattathra.johnson@gmail.com>
  • Loading branch information
alex-kattathra-johnson committed Nov 12, 2024
1 parent 23d2479 commit a0b584f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,25 @@ fn test_mock_with_header() {
assert!(headers.contains(&"content-type: application/json".to_string()));
}

#[test]
fn test_mock_with_header_from_request() {
let mut s = Server::new();
s.mock("GET", Matcher::Any)
.with_header_from_request("user", |req| {
if req.path() == "/alice" {
"alice".into()
} else {
"everyone".into()
}
})
.create();

let (_, headers, _) = request(s.host_with_port(), "GET /alice", "");
assert!(headers.contains(&"user: alice".to_string()));
let (_, headers, _) = request(s.host_with_port(), "GET /anyone-else", "");
assert!(headers.contains(&"user: everyone".to_string()));
}

#[test]
fn test_mock_with_multiple_headers() {
let mut s = Server::new();
Expand Down

0 comments on commit a0b584f

Please sign in to comment.