add test for fn_guard

This commit is contained in:
Rob Ede 2021-12-28 01:44:51 +00:00
parent 12a8ec259c
commit a9a05df88a
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 14 additions and 0 deletions

View File

@ -628,4 +628,18 @@ mod tests {
let not_not_get = Not(not_get); let not_not_get = Not(not_get);
assert!(not_not_get.check(&req.guard_ctx())); 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()));
}
} }