2019-08-20 23:53:00 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2016-08-27 23:20:01 +00:00
|
|
|
|
2018-06-28 15:55:15 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2016-08-27 23:20:01 +00:00
|
|
|
|
2016-09-04 11:06:28 +00:00
|
|
|
#[get("/")]
|
2016-08-27 23:20:01 +00:00
|
|
|
fn hello() -> &'static str {
|
|
|
|
"Hello, world!"
|
|
|
|
}
|
|
|
|
|
2017-06-06 20:41:04 +00:00
|
|
|
fn rocket() -> rocket::Rocket {
|
|
|
|
rocket::ignite().mount("/", routes![hello])
|
|
|
|
}
|
|
|
|
|
2016-08-27 23:20:01 +00:00
|
|
|
fn main() {
|
2019-08-25 02:19:11 +00:00
|
|
|
let _ = rocket().launch();
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2016-10-16 10:16:16 +00:00
|
|
|
use super::rocket;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::local::Client;
|
2016-12-23 10:39:10 +00:00
|
|
|
use rocket::http::Status;
|
2016-08-27 23:20:01 +00:00
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
#[rocket::async_test]
|
|
|
|
async fn test_hello() {
|
2020-06-14 15:57:53 +00:00
|
|
|
let client = Client::new(rocket()).await.unwrap();
|
2019-08-24 17:27:10 +00:00
|
|
|
let mut response = client.get("/").dispatch().await;
|
2016-12-23 10:39:10 +00:00
|
|
|
assert_eq!(response.status(), Status::Ok);
|
2019-08-24 17:27:10 +00:00
|
|
|
assert_eq!(response.body_string().await, Some("Hello, world!".into()));
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
|
|
|
}
|