From dd0fb887b10132b6b2451d4f68c3f5dfff563f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20HUBERT=20/=20PALO-IT?= Date: Tue, 13 Dec 2022 14:57:08 +0100 Subject: [PATCH] add header filter tests --- .../src/http_server/routes/router.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/mithril-aggregator/src/http_server/routes/router.rs b/mithril-aggregator/src/http_server/routes/router.rs index 8c574f1a1d4..c4e318f6636 100644 --- a/mithril-aggregator/src/http_server/routes/router.rs +++ b/mithril-aggregator/src/http_server/routes/router.rs @@ -66,3 +66,40 @@ pub async fn handle_custom(reject: Rejection) -> Result { Err(reject) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn test_no_version() { + let filters = header_must_be(); + warp::test::request() + .path("/aggregator/whatever") + .filter(&filters) + .await + .unwrap(); + } + + #[tokio::test] + async fn test_bad_version() { + let filters = header_must_be(); + warp::test::request() + .header("mithril-api-version", "0.0.999") + .path("/aggregator/whatever") + .filter(&filters) + .await + .unwrap_err(); + } + + #[tokio::test] + async fn test_good_version() { + let filters = header_must_be(); + warp::test::request() + .header("mithril-api-version", MITHRIL_API_VERSION) + .path("/aggregator/whatever") + .filter(&filters) + .await + .unwrap(); + } +}