Skip to content

Commit 8d4da41

Browse files
committed
add testcase for path ""
1 parent dfeb305 commit 8d4da41

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

site/src/server.rs

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

0 commit comments

Comments
 (0)