From f9cdffcd248bfbf80f939b86be28cfdf37e316c0 Mon Sep 17 00:00:00 2001 From: Adrian Hedqvist Date: Wed, 29 Mar 2023 18:31:20 +0200 Subject: [PATCH] add test for routes --- posts/status-update-2020-05-16/index.md | 3 ++- src/handlers/mod.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/posts/status-update-2020-05-16/index.md b/posts/status-update-2020-05-16/index.md index 3a3a827..adbe01c 100644 --- a/posts/status-update-2020-05-16/index.md +++ b/posts/status-update-2020-05-16/index.md @@ -5,7 +5,8 @@ title = 'Status update: 2020-05-16' tags = ["hugo", "zola", "roguelike", "spork"] +++ -Oh boy, it's been a while since I wrote anything on this website, over two years ago! +Oh boy, it's been a while since I wrote anything on this website, + over two years ago! But I've been thinking of starting to write posts more often, try this proggramming-blogging thing out that seems to have had some sort of resurgance. diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 69a9da5..3423ec3 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -98,10 +98,28 @@ impl IntoResponse for WebsiteError { #[cfg(test)] mod tests { + use std::sync::Arc; + + use crate::AppState; + #[test] fn render_index() { let tera = tera::Tera::new("templates/**/*").unwrap(); let ctx = tera::Context::new(); let _res = tera.render("index.html", &ctx).unwrap(); } + + #[tokio::test] + async fn setup_routes() { + // Load the actual posts, just to make this test fail if + // aliases overlap with themselves or other routes + let state = Arc::new(AppState { + tera: tera::Tera::new("templates/**/*").unwrap(), + posts: crate::post::load_all().await.unwrap(), + }); + + super::routes(&state) + .with_state(state) + .into_make_service(); + } }