mirror of https://github.com/fafhrd91/actix-web
add test for fn_guard
This commit is contained in:
parent
12a8ec259c
commit
a9a05df88a
14
src/guard.rs
14
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()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue