aboutsummaryrefslogtreecommitdiffstats
path: root/askama_axum/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-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!");
+}