Skip to content

Commit

Permalink
test(ic-http-gateway): add test to verify path and query extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev committed May 30, 2024
1 parent da864b6 commit 679bb76
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/ic-http-gateway/src/protocol/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,37 @@ fn handle_agent_error(error: AgentError) -> HttpGatewayResult<CanisterResponse>
e => Err(e.into()),
}
}

#[cfg(test)]
mod tests {
use super::*;
use http::Request;

#[test]
fn test_convert_request() {
let request = Request::builder()
.uri("http://example.com/foo/bar/baz?q=hello+world&t=1")
.header("Accept", "text/html")
.header("Accept-Encoding", "gzip, deflate, br, zstd")
.body(b"body".to_vec())
.unwrap();

let http_request = convert_request(request).unwrap();

assert_eq!(
http_request,
HttpRequest {
method: "GET".to_string(),
url: "/foo/bar/baz?q=hello+world&t=1".to_string(),
headers: vec![
("accept".to_string(), "text/html".to_string()),
(
"accept-encoding".to_string(),
"gzip, deflate, br, zstd".to_string()
),
],
body: b"body".to_vec(),
}
);
}
}

0 comments on commit 679bb76

Please sign in to comment.