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-04 00:09:13 +00:00
|
|
|
use super::rocket::{Rocket, Request};
|
|
|
|
use super::rocket::http::Method;
|
2016-08-27 23:20:01 +00:00
|
|
|
|
|
|
|
fn run_test<F>(f: F) where F: Fn(Rocket) {
|
2016-10-04 02:48:33 +00:00
|
|
|
let rocket = Rocket::ignite().mount("/", routes![super::hello]);
|
2016-08-27 23:20:01 +00:00
|
|
|
f(rocket);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
run_test(|_rocket: Rocket| {
|
|
|
|
let _req = Request::mock(Method::Get, "/");
|
|
|
|
// TODO: Allow something like this:
|
|
|
|
// let result = rocket.route(&req);
|
|
|
|
// assert_eq!(result.as_str(), "Hello, world!")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|