aboutsummaryrefslogtreecommitdiffstats
path: root/askama_rocket/tests/basic.rs
blob: 1ded705a3c30b20736840ae01e9b0e68b2630e51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use askama::Template;

use futures_lite::future::block_on;
use rocket::http::{ContentType, Status};
use rocket::local::asynchronous::Client;
use rocket::Responder;

#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
    name: &'a str,
}

#[derive(Responder)]
struct HelloResponder<'a> {
    template: HelloTemplate<'a>,
}

#[rocket::get("/")]
fn hello() -> HelloTemplate<'static> {
    HelloTemplate { name: "world" }
}

#[test]
fn test_rocket() {
    block_on(async {
        let rocket = rocket::build()
            .mount("/", rocket::routes![hello])
            .ignite()
            .await
            .unwrap();
        let client = Client::untracked(rocket).await.unwrap();
        let rsp = client.get("/").dispatch().await;
        assert_eq!(rsp.status(), Status::Ok);
        assert_eq!(rsp.content_type(), Some(ContentType::HTML));
        assert_eq!(rsp.into_string().await.as_deref(), Some("Hello, world!"));
    });
}