Slight cleanup of manual_routes example.

This commit is contained in:
Sergio Benitez 2017-03-08 15:22:36 -08:00
parent 1683102e74
commit ca2bde6386
1 changed files with 9 additions and 11 deletions

View File

@ -34,30 +34,28 @@ fn test_echo() {
#[test] #[test]
fn test_upload() { fn test_upload() {
let rocket = rocket();
let expected_body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, \ let expected_body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, \
sed do eiusmod tempor incididunt ut labore et dolore \ sed do eiusmod tempor incididunt ut labore et dolore \
magna aliqua"; magna aliqua".to_string();
let rocket = rocket();
// Upload the body.
let mut request = MockRequest::new(Post, "/upload") let mut request = MockRequest::new(Post, "/upload")
.header(ContentType::Plain) .header(ContentType::Plain)
.body(expected_body); .body(&expected_body);
let response = request.dispatch_with(&rocket); let response = request.dispatch_with(&rocket);
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
// Ensure we get back the same body.
let mut request = MockRequest::new(Get, "/upload"); let mut request = MockRequest::new(Get, "/upload");
let mut response = request.dispatch_with(&rocket); let mut response = request.dispatch_with(&rocket);
let expected = expected_body.to_string();
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body().and_then(|b| b.into_string()), Some(expected)); assert_eq!(response.body().and_then(|b| b.into_string()), Some(expected_body));
} }
#[test] #[test]
fn test_not_found() { fn test_not_found() {
let uri = "/wrong_address"; let uri = "/wrong_address";
test(uri, let expected_body = format!("Couldn't find: {}", uri);
ContentType::Plain, test(uri, ContentType::Plain, Status::NotFound, expected_body);
Status::NotFound,
format!("Couldn't find: {}", uri));
} }