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!"
|
|
|
|
}
|
|
|
|
|
2020-06-16 12:01:26 +00:00
|
|
|
#[rocket::launch]
|
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
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2016-10-16 10:16:16 +00:00
|
|
|
use super::rocket;
|
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]
|
2020-07-05 18:35:36 +00:00
|
|
|
async fn test_hello_async() {
|
|
|
|
use rocket::local::asynchronous::Client;
|
|
|
|
|
2020-06-14 15:57:53 +00:00
|
|
|
let client = Client::new(rocket()).await.unwrap();
|
2020-06-22 11:54:34 +00:00
|
|
|
let response = client.get("/").dispatch().await;
|
2016-12-23 10:39:10 +00:00
|
|
|
assert_eq!(response.status(), Status::Ok);
|
2020-06-22 11:54:34 +00:00
|
|
|
assert_eq!(response.into_string().await, Some("Hello, world!".into()));
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
2020-07-05 18:35:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello_blocking() {
|
|
|
|
use rocket::local::blocking::Client;
|
|
|
|
|
|
|
|
let client = Client::new(rocket()).unwrap();
|
|
|
|
let response = client.get("/").dispatch();
|
|
|
|
assert_eq!(response.status(), Status::Ok);
|
|
|
|
assert_eq!(response.into_string(), Some("Hello, world!".into()));
|
|
|
|
}
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|