Rocket/examples/testing/src/main.rs

32 lines
683 B
Rust

#![feature(proc_macro_hygiene)]
#[macro_use] extern crate rocket;
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
}
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![hello])
}
fn main() {
let _ = rocket().launch();
}
#[cfg(test)]
mod test {
use super::rocket;
use rocket::local::Client;
use rocket::http::Status;
#[rocket::async_test]
async fn test_hello() {
let client = Client::new(rocket()).await.unwrap();
let mut response = client.get("/").dispatch().await;
assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string().await, Some("Hello, world!".into()));
}
}