diff --git a/src/web/pages.rs b/src/web/pages.rs index df6f405..729c206 100644 --- a/src/web/pages.rs +++ b/src/web/pages.rs @@ -82,7 +82,7 @@ pub async fn resolve_page( // Serve static root landing page from www/index.html pub async fn root_landing() -> Response { let mut target_path = std::path::PathBuf::from("www/index.html"); - + if !target_path.exists() { // Search relative to executable if let Ok(exe_path) = std::env::current_exe() { @@ -120,4 +120,3 @@ pub async fn root_landing() -> Response { Err(_) => (StatusCode::NOT_FOUND, "Not Found").into_response(), } } - diff --git a/tests/root_landing_tests.rs b/tests/root_landing_tests.rs index 73ec074..0a1ee23 100644 --- a/tests/root_landing_tests.rs +++ b/tests/root_landing_tests.rs @@ -6,14 +6,19 @@ use std::fs; async fn test_root_landing_page() { // --- Test case 1: Successful serving --- // Read expected content - let expected_content = fs::read_to_string("www/index.html").expect("www/index.html must exist for test"); + let expected_content = + fs::read_to_string("www/index.html").expect("www/index.html must exist for test"); let response = root_landing().await; assert_eq!(response.status(), StatusCode::OK); - assert!( - response.headers().get("content-type").unwrap().to_str().unwrap().contains("text/html") - ); + assert!(response + .headers() + .get("content-type") + .unwrap() + .to_str() + .unwrap() + .contains("text/html")); // Convert response body to bytes using axum::body::to_bytes let body_bytes = axum::body::to_bytes(response.into_body(), usize::MAX) @@ -28,13 +33,11 @@ async fn test_root_landing_page() { let temp_path = "www/index.html.tmp_test_bak"; fs::rename(orig_path, temp_path).unwrap(); - let response_res = tokio::spawn(async move { - root_landing().await - }).await; + let response_res = tokio::spawn(async move { root_landing().await }).await; // Restore index.html immediately in case of panic/error let rename_res = fs::rename(temp_path, orig_path); - + // Now verify the response status let response = response_res.unwrap(); assert_eq!(response.status(), StatusCode::NOT_FOUND);