aboutsummaryrefslogtreecommitdiffstats
path: root/askama_axum/tests
diff options
context:
space:
mode:
authorLibravatar Michael Alyn Miller <malyn@strangeGizmo.com>2021-11-27 20:59:51 -0800
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2021-11-27 22:03:18 -0800
commit4940b5dd5e792811491f1c3c3b1c70c8177c7e02 (patch)
tree4d28ad21a66ecf9496c265c0844b4c4d036763bc /askama_axum/tests
parent3ef2869f48556a0aae4ca861889f9fd8bea02d66 (diff)
downloadaskama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.tar.gz
askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.tar.bz2
askama-4940b5dd5e792811491f1c3c3b1c70c8177c7e02.zip
Add Axum integration
Diffstat (limited to 'askama_axum/tests')
-rw-r--r--askama_axum/tests/basic.rs35
1 files changed, 35 insertions, 0 deletions
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!");
+}