style: fix cargo fmt issues in pages.rs and root_landing_tests.rs

This commit is contained in:
thakares committed 2026-06-13 22:29:03 +05:30
1 parent 3c0a1bdd91
commit 02a26cfd94
2 files changed
+12 -10

No files matched your search

+1 -2
View File
@@ -82,7 +82,7 @@ pub async fn resolve_page(
// Serve static root landing page from www/index.html // Serve static root landing page from www/index.html
pub async fn root_landing() -> Response { pub async fn root_landing() -> Response {
let mut target_path = std::path::PathBuf::from("www/index.html"); let mut target_path = std::path::PathBuf::from("www/index.html");
if !target_path.exists() { if !target_path.exists() {
// Search relative to executable // Search relative to executable
if let Ok(exe_path) = std::env::current_exe() { 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(), Err(_) => (StatusCode::NOT_FOUND, "Not Found").into_response(),
} }
} }
+11 -8
View File
@@ -6,14 +6,19 @@ use std::fs;
async fn test_root_landing_page() { async fn test_root_landing_page() {
// --- Test case 1: Successful serving --- // --- Test case 1: Successful serving ---
// Read expected content // 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; let response = root_landing().await;
assert_eq!(response.status(), StatusCode::OK); assert_eq!(response.status(), StatusCode::OK);
assert!( assert!(response
response.headers().get("content-type").unwrap().to_str().unwrap().contains("text/html") .headers()
); .get("content-type")
.unwrap()
.to_str()
.unwrap()
.contains("text/html"));
// Convert response body to bytes using axum::body::to_bytes // Convert response body to bytes using axum::body::to_bytes
let body_bytes = axum::body::to_bytes(response.into_body(), usize::MAX) 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"; let temp_path = "www/index.html.tmp_test_bak";
fs::rename(orig_path, temp_path).unwrap(); fs::rename(orig_path, temp_path).unwrap();
let response_res = tokio::spawn(async move { let response_res = tokio::spawn(async move { root_landing().await }).await;
root_landing().await
}).await;
// Restore index.html immediately in case of panic/error // Restore index.html immediately in case of panic/error
let rename_res = fs::rename(temp_path, orig_path); let rename_res = fs::rename(temp_path, orig_path);
// Now verify the response status // Now verify the response status
let response = response_res.unwrap(); let response = response_res.unwrap();
assert_eq!(response.status(), StatusCode::NOT_FOUND); assert_eq!(response.status(), StatusCode::NOT_FOUND);