blob: a61c188223adb2919326d8e7519543bf31ffc38f (
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
|
use askama::Template;
use futures_lite::future::block_on;
use rocket::http::{ContentType, Status};
use rocket::local::asynchronous::Client;
#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
name: &'a str,
}
#[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!"));
});
}
|