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() {
|
2017-06-06 20:41:04 +00:00
|
|
|
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
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
2017-06-06 20:41:04 +00:00
|
|
|
let client = Client::new(rocket()).unwrap();
|
|
|
|
let mut response = client.get("/").dispatch();
|
2016-12-23 10:39:10 +00:00
|
|
|
assert_eq!(response.status(), Status::Ok);
|
2019-08-04 22:29:47 +00:00
|
|
|
assert_eq!(response.body_string_wait(), Some("Hello, world!".into()));
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
|
|
|
}
|