2016-08-27 23:20:01 +00:00
|
|
|
#![feature(plugin)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
2016-08-27 23:20:01 +00:00
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
2016-09-04 11:06:28 +00:00
|
|
|
#[get("/")]
|
2016-08-27 23:20:01 +00:00
|
|
|
fn hello() -> &'static str {
|
|
|
|
"Hello, world!"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2016-10-04 02:48:33 +00:00
|
|
|
rocket::ignite().mount("/", routes![hello]).launch()
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2016-10-16 10:16:16 +00:00
|
|
|
use super::rocket;
|
|
|
|
use rocket::testing::MockRequest;
|
2016-12-23 10:39:10 +00:00
|
|
|
use rocket::http::Status;
|
2016-10-16 10:16:16 +00:00
|
|
|
use rocket::http::Method::*;
|
2016-08-27 23:20:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
2016-10-16 10:16:16 +00:00
|
|
|
let rocket = rocket::ignite().mount("/", routes![super::hello]);
|
2016-12-16 04:53:54 +00:00
|
|
|
let mut req = MockRequest::new(Get, "/");
|
|
|
|
let mut response = req.dispatch_with(&rocket);
|
2016-12-23 10:39:10 +00:00
|
|
|
assert_eq!(response.status(), Status::Ok);
|
2016-12-16 04:53:54 +00:00
|
|
|
|
2016-12-17 17:18:30 +00:00
|
|
|
let body_string = response.body().and_then(|b| b.into_string());
|
2016-12-16 04:53:54 +00:00
|
|
|
assert_eq!(body_string, Some("Hello, world!".to_string()));
|
2016-08-27 23:20:01 +00:00
|
|
|
}
|
|
|
|
}
|