From d39f1e941aa2869068cb54a019db77d5d4363d30 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sat, 10 Aug 2024 20:22:49 +0000
Subject: [PATCH] refactor: Improve header finder tests with `rstest`
Signed-off-by: Awiteb
---
src/finder/header_finder.rs | 128 ++++++++++++++++--------------------
1 file changed, 57 insertions(+), 71 deletions(-)
diff --git a/src/finder/header_finder.rs b/src/finder/header_finder.rs
index a30e5a5..670aa7f 100644
--- a/src/finder/header_finder.rs
+++ b/src/finder/header_finder.rs
@@ -78,85 +78,71 @@ mod tests {
use salvo_core::http::HeaderValue;
#[tokio::test]
- async fn test_captcha_header_finder() {
- let finder = CaptchaHeaderFinder::new();
+ #[rstest::rstest]
+ #[case::not_found(None, None, None, None, None, None)]
+ #[case::normal(
+ None,
+ None,
+ Some(("x-captcha-token", "token")),
+ Some(("x-captcha-answer", "answer")),
+ Some(Some("token")),
+ Some(Some("answer"))
+ )]
+ #[case::custom_headers(
+ Some("custom-token"),
+ Some("custom-answer"),
+ Some(("custom-token", "token")),
+ Some(("custom-answer", "answer")),
+ Some(Some("token")),
+ Some(Some("answer"))
+ )]
+ #[case::custom_not_found(Some("custom-token"), Some("custom-answer"), None, None, None, None)]
+ #[case::custom_not_found_with_headers(
+ Some("custom-token"),
+ Some("custom-answer"),
+ Some(("x-captcha-token", "token")),
+ Some(("x-captcha-answer", "answer")),
+ None,
+ None
+ )]
+ async fn test_header_finder(
+ #[case] custom_token_header: Option<&'static str>,
+ #[case] custom_answer_header: Option<&'static str>,
+ #[case] token_header_name_value: Option<(&'static str, &'static str)>,
+ #[case] answer_header_name_value: Option<(&'static str, &'static str)>,
+ #[case] excepted_token: Option