From 5cdcffc7603022432695746b408abf8909e126a3 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sun, 15 Aug 2021 23:06:16 +0200 Subject: [PATCH] tests: directory listing use cases --- tests/dir_listing.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/dir_listing.rs diff --git a/tests/dir_listing.rs b/tests/dir_listing.rs new file mode 100644 index 0000000..23f7e4d --- /dev/null +++ b/tests/dir_listing.rs @@ -0,0 +1,44 @@ +#![deny(warnings)] + +#[cfg(test)] +mod tests { + use headers::HeaderMap; + use http::{Method, StatusCode}; + use std::path::PathBuf; + + extern crate static_web_server; + use static_web_server::static_files; + + fn root_dir() -> PathBuf { + PathBuf::from("docker/public/") + } + + #[tokio::test] + async fn dir_listing_redirect_permanent_uri() { + let methods = [ + Method::CONNECT, + Method::DELETE, + Method::GET, + Method::HEAD, + Method::OPTIONS, + Method::PATCH, + Method::POST, + Method::PUT, + Method::TRACE, + ]; + for method in methods { + match static_files::handle(&method, &HeaderMap::new(), root_dir(), "/assets", true) + .await + { + Ok(res) => { + assert_eq!(res.status(), 308); + assert_eq!(res.headers()["location"], "/assets/"); + } + Err(status) => { + assert!(method != Method::GET && method != Method::HEAD); + assert_eq!(status, StatusCode::METHOD_NOT_ALLOWED); + } + } + } + } +} -- libgit2 1.7.2