Skip to content

Commit d5cbee8

Browse files
wucke13lovasoa
authored andcommitted
feat: add test for 404 fallback mechanism
1 parent 3ac80fb commit d5cbee8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/404.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT 'alert' AS component,
2+
'We almost got an oopsie' AS title,
3+
'But the `404.sql` file saved the day!' AS description_md;

tests/index.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ async fn test_404() {
5151
}
5252
}
5353

54+
#[actix_web::test]
55+
async fn test_404_fallback() {
56+
for f in [
57+
"/tests/does_not_exist.sql",
58+
"/tests/does_not_exist.html",
59+
"/tests/does_not_exist/",
60+
] {
61+
let resp_result = req_path(f).await;
62+
let resp = resp_result.unwrap();
63+
assert_eq!(resp.status(), http::StatusCode::OK, "{f} isnt 200");
64+
65+
let body = test::read_body(resp).await;
66+
assert!(body.starts_with(b"<!DOCTYPE html>"));
67+
// the body should contain our happy string, but not the string "error"
68+
let body = String::from_utf8(body.to_vec()).unwrap();
69+
assert!(body.contains("But the "));
70+
assert!(body.contains("404.sql"));
71+
assert!(body.contains("file saved the day!"));
72+
assert!(!body.contains("error"));
73+
}
74+
}
75+
5476
#[actix_web::test]
5577
async fn test_concurrent_requests() {
5678
// send 32 requests (less than the default postgres pool size)

0 commit comments

Comments
 (0)