mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 01:21:10 +00:00
add tests for files_listing_renderer
This commit is contained in:
parent
4bff1d0abe
commit
b933ed4456
1 changed files with 41 additions and 2 deletions
|
@ -142,7 +142,7 @@ impl Files {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set custom directory renderer
|
||||
/// Set custom directory renderer.
|
||||
pub fn files_listing_renderer<F>(mut self, f: F) -> Self
|
||||
where
|
||||
for<'r, 's> F:
|
||||
|
@ -152,7 +152,7 @@ impl Files {
|
|||
self
|
||||
}
|
||||
|
||||
/// Specifies mime override callback
|
||||
/// Specifies MIME override callback.
|
||||
pub fn mime_override<F>(mut self, f: F) -> Self
|
||||
where
|
||||
F: Fn(&mime::Name<'_>) -> DispositionType + 'static,
|
||||
|
@ -390,3 +390,42 @@ impl ServiceFactory<ServiceRequest> for Files {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::{
|
||||
http::StatusCode,
|
||||
test::{self, TestRequest},
|
||||
App, HttpResponse,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn custom_files_listing_renderer() {
|
||||
let srv = test::init_service(
|
||||
App::new().service(
|
||||
Files::new("/", "./tests")
|
||||
.show_files_listing()
|
||||
.files_listing_renderer(|dir, req| {
|
||||
Ok(ServiceResponse::new(
|
||||
req.clone(),
|
||||
HttpResponse::Ok().body(dir.path.to_str().unwrap().to_owned()),
|
||||
))
|
||||
}),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = TestRequest::with_uri("/").to_request();
|
||||
let res = test::call_service(&srv, req).await;
|
||||
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
let body = test::read_body(res).await;
|
||||
assert!(
|
||||
body.ends_with(b"actix-files/tests/"),
|
||||
"body {:?} does not end with `actix-files/tests/`",
|
||||
body
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue