From a9a05df88a216598a210856cdc6ce84b42fcb5cc Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 28 Dec 2021 01:44:51 +0000 Subject: [PATCH] add test for fn_guard --- src/guard.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/guard.rs b/src/guard.rs index f008ff5ce..fb3e4f243 100644 --- a/src/guard.rs +++ b/src/guard.rs @@ -628,4 +628,18 @@ mod tests { let not_not_get = Not(not_get); assert!(not_not_get.check(&req.guard_ctx())); } + + #[test] + fn function_guard() { + let domain = "rust-lang.org".to_owned(); + let guard = fn_guard(|ctx| ctx.head().uri.host().unwrap().ends_with(&domain)); + + let req = TestRequest::default() + .uri("blog.rust-lang.org") + .to_srv_request(); + assert!(guard.check(&req.guard_ctx())); + + let req = TestRequest::default().uri("crates.io").to_srv_request(); + assert!(!guard.check(&req.guard_ctx())); + } }