Rocket/examples/testing/src/main.rs

30 lines
620 B
Rust

#[macro_use] extern crate rocket;
mod async_required;
#[get("/")]
fn hello() -> &'static str {
"Hello, world!"
}
#[launch]
fn rocket() -> rocket::Rocket {
async_required::rocket().mount("/", routes![hello])
}
#[cfg(test)]
mod test {
use super::rocket;
use rocket::http::Status;
#[test]
fn test_hello() {
use rocket::local::blocking::Client;
let client = Client::tracked(rocket()).unwrap();
let response = client.get("/").dispatch();
assert_eq!(response.status(), Status::Ok);
assert_eq!(response.into_string(), Some("Hello, world!".into()));
}
}