diff options
author | Kellen Frodelius-Fujimoto <kellen@kellenfujimoto.com> | 2018-12-10 20:21:15 +0100 |
---|---|---|
committer | Juan Aguilar <mhpoin@gmail.com> | 2018-12-10 22:29:24 +0100 |
commit | 9b0001cdf3991e74c042a9661e306b13785ca223 (patch) | |
tree | d8ccfbdec0c5ad4d81150b92c2c74952abfc5da2 /testing/tests | |
parent | 5549f9a3cd94e3cd6700067b1c74194dadb58a0f (diff) | |
download | askama-9b0001cdf3991e74c042a9661e306b13785ca223.tar.gz askama-9b0001cdf3991e74c042a9661e306b13785ca223.tar.bz2 askama-9b0001cdf3991e74c042a9661e306b13785ca223.zip |
Implement `IntoResponse` for `Template`, allowing them to be used in `gotham` handlers.
Diffstat (limited to 'testing/tests')
-rw-r--r-- | testing/tests/gotham.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/testing/tests/gotham.rs b/testing/tests/gotham.rs new file mode 100644 index 0000000..f127d59 --- /dev/null +++ b/testing/tests/gotham.rs @@ -0,0 +1,39 @@ +#![cfg(feature = "with-gotham")] + +use askama::Template; +use gotham::state::State; +use gotham::test::TestServer; +use hyper::StatusCode; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} + +fn hello(state: State) -> (State, HelloTemplate<'static>) { + (state, HelloTemplate { name: "world" }) +} + +#[test] +fn test_gotham() { + let test_server = TestServer::new(|| Ok(hello)).expect("Failed to mount test router"); + + let res = test_server + .client() + .get("http://localhost/") + .perform() + .expect("Failed to send request to gotham"); + + assert_eq!(res.status(), StatusCode::OK); + { + let headers = res.headers(); + let content_type = headers + .get("content-type") + .expect("Response did not contain content-type header"); + assert_eq!(content_type.to_str().unwrap(), mime::TEXT_HTML.to_string()); + } + + let body = res.read_utf8_body().expect("failed to read response body"); + assert_eq!(&body, "Hello, world!"); +} |