From 585298244b728e07c72f13b62bc6c54801bd51d0 Mon Sep 17 00:00:00 2001 From: NathanosDev Date: Thu, 30 May 2024 11:35:48 +0200 Subject: [PATCH] test(ic-http-gateway): add test to verify path and query extraction --- .../ic-http-gateway/src/protocol/handler.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/ic-http-gateway/src/protocol/handler.rs b/packages/ic-http-gateway/src/protocol/handler.rs index 04a925a..98f6061 100644 --- a/packages/ic-http-gateway/src/protocol/handler.rs +++ b/packages/ic-http-gateway/src/protocol/handler.rs @@ -317,3 +317,37 @@ fn handle_agent_error(error: AgentError) -> HttpGatewayResult 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(), + } + ); + } +}