From 5e03b7c495d096b6c97c927c23f9edf1c322d411 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Fri, 21 May 2021 10:40:36 +0300 Subject: [PATCH] Add test --- actix-files/src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/actix-files/src/lib.rs b/actix-files/src/lib.rs index aa5960b5b..deeb378ec 100644 --- a/actix-files/src/lib.rs +++ b/actix-files/src/lib.rs @@ -856,4 +856,33 @@ mod tests { "inline; filename=\"symlink-test.png\"" ); } + + #[actix_rt::test] + async fn test_index_with_show_files_listing() { + let service = Files::new(".", ".") + .index_file("lib.rs") + .show_files_listing() + .new_service(()) + .await + .unwrap(); + + // Serve the index if exists + let req = TestRequest::default().uri("/src").to_srv_request(); + let resp = test::call_service(&service, req).await; + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!( + resp.headers().get(header::CONTENT_TYPE).unwrap(), + "text/x-rust" + ); + + // Show files listing, otherwise. + let req = TestRequest::default().uri("/tests").to_srv_request(); + let resp = test::call_service(&service, 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")); + } }