Skip to content

Commit

Permalink
feat: add test for 404 fallback mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
wucke13 authored and lovasoa committed Aug 22, 2024
1 parent 3ac80fb commit d5cbee8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/404.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT 'alert' AS component,
'We almost got an oopsie' AS title,
'But the `404.sql` file saved the day!' AS description_md;
22 changes: 22 additions & 0 deletions tests/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ async fn test_404() {
}
}

#[actix_web::test]
async fn test_404_fallback() {
for f in [
"/tests/does_not_exist.sql",
"/tests/does_not_exist.html",
"/tests/does_not_exist/",
] {
let resp_result = req_path(f).await;
let resp = resp_result.unwrap();
assert_eq!(resp.status(), http::StatusCode::OK, "{f} isnt 200");

let body = test::read_body(resp).await;
assert!(body.starts_with(b"<!DOCTYPE html>"));
// the body should contain our happy string, but not the string "error"
let body = String::from_utf8(body.to_vec()).unwrap();
assert!(body.contains("But the "));
assert!(body.contains("404.sql"));
assert!(body.contains("file saved the day!"));
assert!(!body.contains("error"));
}
}

#[actix_web::test]
async fn test_concurrent_requests() {
// send 32 requests (less than the default postgres pool size)
Expand Down

0 comments on commit d5cbee8

Please sign in to comment.