[actix-files] add test for custom guards in Files

This commit is contained in:
Naim A 2019-10-08 01:18:53 +03:00
parent 86436bb4fe
commit d4adab28de
1 changed files with 19 additions and 0 deletions

View File

@ -611,6 +611,7 @@ mod tests {
use bytes::BytesMut; use bytes::BytesMut;
use super::*; use super::*;
use actix_web::guard;
use actix_web::http::header::{ use actix_web::http::header::{
self, ContentDisposition, DispositionParam, DispositionType, self, ContentDisposition, DispositionParam, DispositionType,
}; };
@ -1066,6 +1067,24 @@ mod tests {
assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED); assert_eq!(resp.status(), StatusCode::METHOD_NOT_ALLOWED);
} }
#[test]
fn test_files_guards() {
let mut srv = test::init_service(
App::new().service(
Files::new("/", ".")
.use_guards(guard::Post())
),
);
let req = TestRequest::default()
.uri("/Cargo.toml")
.method(Method::POST)
.to_request();
let resp = test::call_service(&mut srv, req);
assert_eq!(resp.status(), StatusCode::OK);
}
#[test] #[test]
fn test_named_file_content_encoding() { fn test_named_file_content_encoding() {
let mut srv = test::init_service(App::new().wrap(Compress::default()).service( let mut srv = test::init_service(App::new().wrap(Compress::default()).service(