From e2ac85a0b48093e30c9e307e0c73fde096dcd2a2 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 18 Oct 2021 03:54:26 +0800 Subject: [PATCH] fix tests --- actix-files/src/files.rs | 8 +++++++- actix-files/src/lib.rs | 36 ------------------------------------ actix-files/src/named.rs | 8 ++++---- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/actix-files/src/files.rs b/actix-files/src/files.rs index edf047504..06909bf08 100644 --- a/actix-files/src/files.rs +++ b/actix-files/src/files.rs @@ -283,11 +283,17 @@ impl Files { /// Setting a fallback static file handler: /// ``` /// use actix_files::{Files, NamedFile}; + /// use actix_web::dev::{ServiceRequest, ServiceResponse, fn_service}; /// /// # fn run() -> Result<(), actix_web::Error> { /// let files = Files::new("/", "./static") /// .index_file("index.html") - /// .default_handler(NamedFile::open("./static/404.html")?); + /// .default_handler(fn_service(|req: ServiceRequest| async { + /// let (req, _) = req.into_parts(); + /// let file = NamedFile::open_async("./static/404.html").await?; + /// let res = file.into_response(&req); + /// Ok(ServiceResponse::new(req, res)) + /// })); /// # Ok(()) /// # } /// ``` diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index f72a2dc9a..106542718 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -668,42 +668,6 @@ mod tests { assert!(format!("{:?}", bytes).contains("/tests/test.png")); } - // TODO: reduce duplicate test between features. - #[cfg(feature = "io-uring")] - #[test] - fn test_static_files_io_uring() { - tokio_uring::start(async { - let srv = test::init_service( - App::new().service(Files::new("/", ".").show_files_listing()), - ) - .await; - let req = TestRequest::with_uri("/missing").to_request(); - - let resp = test::call_service(&srv, req).await; - assert_eq!(resp.status(), StatusCode::NOT_FOUND); - - let srv = test::init_service(App::new().service(Files::new("/", "."))).await; - - let req = TestRequest::default().to_request(); - let resp = test::call_service(&srv, req).await; - assert_eq!(resp.status(), StatusCode::NOT_FOUND); - - let srv = test::init_service( - App::new().service(Files::new("/", ".").show_files_listing()), - ) - .await; - let req = TestRequest::with_uri("/tests").to_request(); - let resp = test::call_service(&srv, req).await; - assert_eq!( - resp.headers().get(header::CONTENT_TYPE).unwrap(), - "text/html; charset=utf-8" - ); - - let bytes = test::read_body(resp).await; - assert!(format!("{:?}", bytes).contains("/tests/test.png")); - }) - } - #[actix_rt::test] async fn test_redirect_to_slash_directory() { // should not redirect if no index and files listing is disabled diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index a0f73e99c..06b32bb30 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -52,9 +52,9 @@ impl Default for Flags { /// use actix_web::App; /// use actix_files::NamedFile; /// -/// # fn run() -> Result<(), Box> { -/// let app = App::new() -/// .service(NamedFile::open("./static/index.html")?); +/// # async fn run() -> Result<(), Box> { +/// let file = NamedFile::open_async("./static/index.html").await?; +/// let app = App::new().service(file); /// # Ok(()) /// # } /// ``` @@ -120,7 +120,7 @@ impl NamedFile { /// /// # Examples /// - /// ``` + /// ```ignore /// use actix_files::NamedFile; /// use std::io::{self, Write}; /// use std::env;