2018-06-28 15:55:15 +00:00
|
|
|
#![feature(plugin, decl_macro, proc_macro_non_items)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
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);
|
2017-04-14 08:59:28 +00:00
|
|
|
assert_eq!(response.body_string(), Some("Hello, world!".into()));
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
|
|
|
}
|