2020-07-05 18:35:36 +00:00
|
|
|
use rocket::local::blocking::Client;
|
2017-06-06 20:41:04 +00:00
|
|
|
use rocket::http::Status;
|
2017-01-02 06:55:08 +00:00
|
|
|
|
2020-07-30 06:07:22 +00:00
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
2020-10-15 04:37:16 +00:00
|
|
|
let client = Client::tracked(super::rocket()).unwrap();
|
2017-01-02 06:55:08 +00:00
|
|
|
|
2020-07-30 06:07:22 +00:00
|
|
|
let (name, age) = ("Arthur", 42);
|
|
|
|
let uri = format!("/hello/{}/{}", name, age);
|
2020-07-05 18:35:36 +00:00
|
|
|
let response = client.get(uri).dispatch();
|
2020-07-30 06:07:22 +00:00
|
|
|
|
|
|
|
assert_eq!(response.status(), Status::Ok);
|
|
|
|
assert_eq!(response.into_string().unwrap(), super::hello(name.into(), age));
|
2017-01-02 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
#[test]
|
2021-03-26 04:36:00 +00:00
|
|
|
fn forced_error() {
|
2020-10-15 04:37:16 +00:00
|
|
|
let client = Client::tracked(super::rocket()).unwrap();
|
2020-07-30 06:07:22 +00:00
|
|
|
|
|
|
|
let request = client.get("/404");
|
2021-03-26 04:36:00 +00:00
|
|
|
let expected = super::general_not_found();
|
2020-07-30 06:07:22 +00:00
|
|
|
let response = request.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::NotFound);
|
|
|
|
assert_eq!(response.into_string().unwrap(), expected.0);
|
|
|
|
|
|
|
|
let request = client.get("/405");
|
|
|
|
let expected = super::default_catcher(Status::MethodNotAllowed, request.inner());
|
|
|
|
let response = request.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::MethodNotAllowed);
|
|
|
|
assert_eq!(response.into_string().unwrap(), expected.1);
|
|
|
|
|
|
|
|
let request = client.get("/533");
|
|
|
|
let expected = super::default_catcher(Status::raw(533), request.inner());
|
|
|
|
let response = request.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::raw(533));
|
|
|
|
assert_eq!(response.into_string().unwrap(), expected.1);
|
|
|
|
|
|
|
|
let request = client.get("/700");
|
|
|
|
let expected = super::default_catcher(Status::InternalServerError, request.inner());
|
|
|
|
let response = request.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::InternalServerError);
|
|
|
|
assert_eq!(response.into_string().unwrap(), expected.1);
|
2017-01-02 06:55:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
#[test]
|
|
|
|
fn test_hello_invalid_age() {
|
2020-10-15 04:37:16 +00:00
|
|
|
let client = Client::tracked(super::rocket()).unwrap();
|
2020-07-30 06:07:22 +00:00
|
|
|
|
2021-03-26 04:36:00 +00:00
|
|
|
for path in &["Ford/-129", "Trillian/128", "foo/bar/baz"] {
|
|
|
|
let request = client.get(format!("/hello/{}", path));
|
|
|
|
let expected = super::hello_not_found(request.inner());
|
2020-07-30 06:07:22 +00:00
|
|
|
let response = request.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::NotFound);
|
|
|
|
assert_eq!(response.into_string().unwrap(), expected.0);
|
2017-01-02 06:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-26 04:36:00 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello_sergio() {
|
|
|
|
let client = Client::tracked(super::rocket()).unwrap();
|
|
|
|
|
|
|
|
for path in &["oops", "-129", "foo/bar", "/foo/bar/baz"] {
|
|
|
|
let request = client.get(format!("/hello/Sergio/{}", path));
|
|
|
|
let expected = super::sergio_error();
|
|
|
|
let response = request.dispatch();
|
|
|
|
assert_eq!(response.status(), Status::NotFound);
|
|
|
|
assert_eq!(response.into_string().unwrap(), expected);
|
|
|
|
}
|
|
|
|
}
|