From 4940b5dd5e792811491f1c3c3b1c70c8177c7e02 Mon Sep 17 00:00:00 2001 From: Michael Alyn Miller Date: Sat, 27 Nov 2021 20:59:51 -0800 Subject: Add Axum integration --- askama_axum/tests/basic.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 askama_axum/tests/basic.rs (limited to 'askama_axum/tests/basic.rs') diff --git a/askama_axum/tests/basic.rs b/askama_axum/tests/basic.rs new file mode 100644 index 0000000..acd53b7 --- /dev/null +++ b/askama_axum/tests/basic.rs @@ -0,0 +1,35 @@ +use askama::Template; +use axum::{ + body::Body, + http::{Request, StatusCode}, + routing::get, + Router, +}; +use tower::util::ServiceExt; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} + +async fn hello() -> HelloTemplate<'static> { + HelloTemplate { name: "world" } +} + +#[tokio::test] +async fn template_to_response() { + let app = Router::new().route("/", get(hello)); + + let res = app + .oneshot(Request::builder().uri("/").body(Body::empty()).unwrap()) + .await + .unwrap(); + assert_eq!(res.status(), StatusCode::OK); + + let headers = res.headers(); + assert_eq!(headers["Content-Type"], "text/html; charset=utf-8"); + + let body = hyper::body::to_bytes(res.into_body()).await.unwrap(); + assert_eq!(&body[..], b"Hello, world!"); +} -- cgit