Skip to content

Commit 2ed8f42

Browse files
committed
add testcase for path ""
1 parent bfe4ee4 commit 2ed8f42

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

site/src/server.rs

+23
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,26 @@ impl ResponseHeaders for http::response::Builder {
807807
self
808808
}
809809
}
810+
811+
#[cfg(test)]
812+
mod tests {
813+
use super::*;
814+
#[tokio::test]
815+
async fn handle_fs_path_html() {
816+
// Test case 1: Path is ""
817+
let req = Request::default();
818+
let path = "";
819+
let use_compression = false;
820+
let response = handle_fs_path(&req, path, use_compression).await.unwrap();
821+
// "", "/", "/index.html", "/graphs.html" map to "graphs.html"
822+
let expected_body = TEMPLATES.get_template("graphs.html").await.unwrap();
823+
let expected_response = http::Response::builder()
824+
.header_typed(ETag::from_str(&format!(r#""{}""#, *VERSION_UUID)).unwrap())
825+
.header(CACHE_CONTROL, "max-age=60, stale-while-revalidate=86400")
826+
.header_typed(ContentType::html())
827+
.body(hyper::Body::from(expected_body))
828+
.unwrap();
829+
assert_eq!(response.headers(), expected_response.headers());
830+
assert_eq!(hyper::body::to_bytes(response.into_body()).await.unwrap(), hyper::body::to_bytes(expected_response.into_body()).await.unwrap());
831+
}
832+
}

0 commit comments

Comments
 (0)