From bc404f1f6d31fd33fb455b3566cf0c3ed69e38a1 Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Sun, 4 Aug 2019 15:29:47 -0700 Subject: [PATCH] Use 'body_string_wait' in all example tests. --- examples/content_types/src/tests.rs | 2 +- examples/errors/src/tests.rs | 2 +- examples/fairings/src/tests.rs | 8 ++++---- examples/form_kitchen_sink/src/tests.rs | 2 +- examples/form_validation/src/tests.rs | 2 +- examples/hello_2015/src/tests.rs | 6 +++--- examples/hello_2018/src/tests.rs | 6 +++--- examples/hello_person/src/tests.rs | 2 +- examples/hello_world/src/tests.rs | 2 +- examples/managed_queue/src/tests.rs | 2 +- examples/manual_routes/src/tests.rs | 4 ++-- examples/optional_redirect/src/tests.rs | 2 +- examples/pastebin/src/tests.rs | 6 +++--- examples/query_params/src/tests.rs | 18 +++++++++--------- examples/ranking/src/tests.rs | 2 +- examples/raw_sqlite/src/tests.rs | 2 +- examples/raw_upload/src/tests.rs | 4 ++-- examples/redirect/src/tests.rs | 2 +- examples/request_guard/src/main.rs | 2 +- examples/state/src/tests.rs | 2 +- examples/stream/src/tests.rs | 4 ++-- examples/testing/src/main.rs | 2 +- examples/tls/src/tests.rs | 2 +- examples/uuid/src/tests.rs | 2 +- 24 files changed, 44 insertions(+), 44 deletions(-) diff --git a/examples/content_types/src/tests.rs b/examples/content_types/src/tests.rs index afe31228..5bae9a7f 100644 --- a/examples/content_types/src/tests.rs +++ b/examples/content_types/src/tests.rs @@ -12,7 +12,7 @@ fn test(method: Method, uri: &str, header: H, status: Status, body: String) let client = Client::new(rocket).unwrap(); let mut response = client.req(method, uri).header(header).dispatch(); assert_eq!(response.status(), status); - assert_eq!(response.body_string(), Some(body)); + assert_eq!(response.body_string_wait(), Some(body)); } #[test] diff --git a/examples/errors/src/tests.rs b/examples/errors/src/tests.rs index 78f41422..e93ab2a8 100644 --- a/examples/errors/src/tests.rs +++ b/examples/errors/src/tests.rs @@ -9,7 +9,7 @@ fn test(uri: &str, status: Status, body: String) { let client = Client::new(rocket).unwrap(); let mut response = client.get(uri).dispatch(); assert_eq!(response.status(), status); - assert_eq!(response.body_string(), Some(body)); + assert_eq!(response.body_string_wait(), Some(body)); } #[test] diff --git a/examples/fairings/src/tests.rs b/examples/fairings/src/tests.rs index 37622e50..421e2aa6 100644 --- a/examples/fairings/src/tests.rs +++ b/examples/fairings/src/tests.rs @@ -5,7 +5,7 @@ use rocket::local::Client; fn rewrite_get_put() { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello, fairings!".into())); + assert_eq!(response.body_string_wait(), Some("Hello, fairings!".into())); } #[test] @@ -17,7 +17,7 @@ fn counts() { // Check the GET count, taking into account _this_ GET request. let mut response = client.get("/counts").dispatch(); - assert_eq!(response.body_string(), Some("Get: 2\nPost: 0".into())); + assert_eq!(response.body_string_wait(), Some("Get: 2\nPost: 0".into())); // Issue 1 more GET request and a POST. client.get("/").dispatch(); @@ -25,7 +25,7 @@ fn counts() { // Check the counts. let mut response = client.get("/counts").dispatch(); - assert_eq!(response.body_string(), Some("Get: 4\nPost: 1".into())); + assert_eq!(response.body_string_wait(), Some("Get: 4\nPost: 1".into())); } #[test] @@ -34,5 +34,5 @@ fn token() { // Ensure the token is '123', which is what we have in `Rocket.toml`. let mut res = client.get("/token").dispatch(); - assert_eq!(res.body_string(), Some("123".into())); + assert_eq!(res.body_string_wait(), Some("123".into())); } diff --git a/examples/form_kitchen_sink/src/tests.rs b/examples/form_kitchen_sink/src/tests.rs index cafbe685..55f15cf5 100644 --- a/examples/form_kitchen_sink/src/tests.rs +++ b/examples/form_kitchen_sink/src/tests.rs @@ -20,7 +20,7 @@ fn assert_form_eq(client: &Client, form_str: &str, expected: String) { .body(form_str) .dispatch(); - assert_eq!(res.body_string(), Some(expected)); + assert_eq!(res.body_string_wait(), Some(expected)); } fn assert_valid_form(client: &Client, input: &FormInput<'_>) { diff --git a/examples/form_validation/src/tests.rs b/examples/form_validation/src/tests.rs index b7c72821..ff945593 100644 --- a/examples/form_validation/src/tests.rs +++ b/examples/form_validation/src/tests.rs @@ -14,7 +14,7 @@ fn test_login(user: &str, pass: &str, age: &str, status: Status, body: T) assert_eq!(response.status(), status); if let Some(expected_str) = body.into() { - let body_str = response.body_string(); + let body_str = response.body_string_wait(); assert!(body_str.map_or(false, |s| s.contains(expected_str))); } } diff --git a/examples/hello_2015/src/tests.rs b/examples/hello_2015/src/tests.rs index ab692957..685d0727 100644 --- a/examples/hello_2015/src/tests.rs +++ b/examples/hello_2015/src/tests.rs @@ -5,7 +5,7 @@ fn hello_world() { let rocket = rocket::ignite().mount("/", routes![super::hello]); let client = Client::new(rocket).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello, Rust 2015!".into())); + assert_eq!(response.body_string_wait(), Some("Hello, Rust 2015!".into())); } // Tests unrelated to the example. @@ -38,13 +38,13 @@ mod scoped_uri_tests { fn test_inner_hello() { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello! Try /Rust%202015.".into())); + assert_eq!(response.body_string_wait(), Some("Hello! Try /Rust%202015.".into())); } #[test] fn test_hello_name() { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/Rust%202015").dispatch(); - assert_eq!(response.body_string().unwrap(), "Hello, Rust 2015! This is /Rust%202015."); + assert_eq!(response.body_string_wait().unwrap(), "Hello, Rust 2015! This is /Rust%202015."); } } diff --git a/examples/hello_2018/src/tests.rs b/examples/hello_2018/src/tests.rs index 804136c3..9fa2575d 100644 --- a/examples/hello_2018/src/tests.rs +++ b/examples/hello_2018/src/tests.rs @@ -5,7 +5,7 @@ fn hello_world() { let rocket = rocket::ignite().mount("/", routes![super::hello]); let client = Client::new(rocket).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello, Rust 2018!".into())); + assert_eq!(response.body_string_wait(), Some("Hello, Rust 2018!".into())); } // Tests unrelated to the example. @@ -38,13 +38,13 @@ mod scoped_uri_tests { fn test_inner_hello() { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello! Try /Rust%202018.".into())); + assert_eq!(response.body_string_wait(), Some("Hello! Try /Rust%202018.".into())); } #[test] fn test_hello_name() { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/Rust%202018").dispatch(); - assert_eq!(response.body_string().unwrap(), "Hello, Rust 2018! This is /Rust%202018."); + assert_eq!(response.body_string_wait().unwrap(), "Hello, Rust 2018! This is /Rust%202018."); } } diff --git a/examples/hello_person/src/tests.rs b/examples/hello_person/src/tests.rs index 35fd3999..c3dbdff2 100644 --- a/examples/hello_person/src/tests.rs +++ b/examples/hello_person/src/tests.rs @@ -7,7 +7,7 @@ fn client() -> Client { fn test(uri: &str, expected: String) { let client = client(); - assert_eq!(client.get(uri).dispatch().body_string(), Some(expected)); + assert_eq!(client.get(uri).dispatch().body_string_wait(), Some(expected)); } fn test_404(uri: &str) { diff --git a/examples/hello_world/src/tests.rs b/examples/hello_world/src/tests.rs index 80bf4aeb..069157da 100644 --- a/examples/hello_world/src/tests.rs +++ b/examples/hello_world/src/tests.rs @@ -5,5 +5,5 @@ fn hello_world() { let rocket = rocket::ignite().mount("/", routes![super::hello]); let client = Client::new(rocket).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello, world!".into())); + assert_eq!(response.body_string_wait(), Some("Hello, world!".into())); } diff --git a/examples/managed_queue/src/tests.rs b/examples/managed_queue/src/tests.rs index e5a0fcd3..101267ef 100644 --- a/examples/managed_queue/src/tests.rs +++ b/examples/managed_queue/src/tests.rs @@ -9,5 +9,5 @@ fn test_push_pop() { assert_eq!(response.status(), Status::Ok); let mut response = client.get("/pop").dispatch(); - assert_eq!(response.body_string(), Some("test1".to_string())); + assert_eq!(response.body_string_wait(), Some("test1".to_string())); } diff --git a/examples/manual_routes/src/tests.rs b/examples/manual_routes/src/tests.rs index df6a1d87..3c95043d 100644 --- a/examples/manual_routes/src/tests.rs +++ b/examples/manual_routes/src/tests.rs @@ -6,7 +6,7 @@ fn test(uri: &str, content_type: ContentType, status: Status, body: String) { let client = Client::new(rocket()).unwrap(); let mut response = client.get(uri).header(content_type).dispatch(); assert_eq!(response.status(), status); - assert_eq!(response.body_string(), Some(body)); + assert_eq!(response.body_string_wait(), Some(body)); } #[test] @@ -46,7 +46,7 @@ fn test_upload() { // Ensure we get back the same body. let mut response = client.get("/upload").dispatch(); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body_string(), Some(expected_body)); + assert_eq!(response.body_string_wait(), Some(expected_body)); } #[test] diff --git a/examples/optional_redirect/src/tests.rs b/examples/optional_redirect/src/tests.rs index 2e2875ee..54591003 100644 --- a/examples/optional_redirect/src/tests.rs +++ b/examples/optional_redirect/src/tests.rs @@ -12,7 +12,7 @@ fn test_200(uri: &str, expected_body: &str) { let client = client(); let mut response = client.get(uri).dispatch(); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body_string(), Some(expected_body.to_string())); + assert_eq!(response.body_string_wait(), Some(expected_body.to_string())); } fn test_303(uri: &str, expected_location: &str) { diff --git a/examples/pastebin/src/tests.rs b/examples/pastebin/src/tests.rs index fa153294..063f4f02 100644 --- a/examples/pastebin/src/tests.rs +++ b/examples/pastebin/src/tests.rs @@ -14,20 +14,20 @@ fn check_index() { let mut response = client.get("/").dispatch(); assert_eq!(response.status(), Status::Ok); assert_eq!(response.content_type(), Some(ContentType::Plain)); - assert_eq!(response.body_string(), Some(index().into())) + assert_eq!(response.body_string_wait(), Some(index().into())) } fn upload_paste(client: &Client, body: &str) -> String { let mut response = client.post("/").body(body).dispatch(); assert_eq!(response.status(), Status::Ok); assert_eq!(response.content_type(), Some(ContentType::Plain)); - extract_id(&response.body_string().unwrap()).unwrap() + extract_id(&response.body_string_wait().unwrap()).unwrap() } fn download_paste(client: &Client, id: &str) -> String { let mut response = client.get(format!("/{}", id)).dispatch(); assert_eq!(response.status(), Status::Ok); - response.body_string().unwrap() + response.body_string_wait().unwrap() } #[test] diff --git a/examples/query_params/src/tests.rs b/examples/query_params/src/tests.rs index 9cb7b617..6df32268 100644 --- a/examples/query_params/src/tests.rs +++ b/examples/query_params/src/tests.rs @@ -12,12 +12,12 @@ macro_rules! run_test { #[test] fn age_and_name_params() { run_test!("?age=10&first-name=john", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("Hello, 10 year old named john!".into())); }); run_test!("?age=20&first-name=john", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("20 years old? Hi, john!".into())); }); } @@ -25,12 +25,12 @@ fn age_and_name_params() { #[test] fn age_param_only() { run_test!("?age=10", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("We're gonna need a name, and only a name.".into())); }); run_test!("?age=20", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("We're gonna need a name, and only a name.".into())); }); } @@ -38,19 +38,19 @@ fn age_param_only() { #[test] fn name_param_only() { run_test!("?first-name=John", |mut response: Response<'_>| { - assert_eq!(response.body_string(), Some("Hello John!".into())); + assert_eq!(response.body_string_wait(), Some("Hello John!".into())); }); } #[test] fn no_params() { run_test!("", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("We're gonna need a name, and only a name.".into())); }); run_test!("?", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("We're gonna need a name, and only a name.".into())); }); } @@ -58,12 +58,12 @@ fn no_params() { #[test] fn extra_params() { run_test!("?age=20&first-name=Bob&extra", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("20 years old? Hi, Bob!".into())); }); run_test!("?age=30&first-name=Bob&extra", |mut response: Response<'_>| { - assert_eq!(response.body_string(), + assert_eq!(response.body_string_wait(), Some("We're gonna need a name, and only a name.".into())); }); } diff --git a/examples/ranking/src/tests.rs b/examples/ranking/src/tests.rs index e638150a..3573dcb6 100644 --- a/examples/ranking/src/tests.rs +++ b/examples/ranking/src/tests.rs @@ -4,7 +4,7 @@ fn test(uri: &str, expected: String) { let rocket = rocket::ignite().mount("/", routes![super::hello, super::hi]); let client = Client::new(rocket).unwrap(); let mut response = client.get(uri).dispatch(); - assert_eq!(response.body_string(), Some(expected)); + assert_eq!(response.body_string_wait(), Some(expected)); } #[test] diff --git a/examples/raw_sqlite/src/tests.rs b/examples/raw_sqlite/src/tests.rs index 3fbb8062..6819a677 100644 --- a/examples/raw_sqlite/src/tests.rs +++ b/examples/raw_sqlite/src/tests.rs @@ -5,5 +5,5 @@ use rocket::local::Client; fn hello() { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Rocketeer".into())); + assert_eq!(response.body_string_wait(), Some("Rocketeer".into())); } diff --git a/examples/raw_upload/src/tests.rs b/examples/raw_upload/src/tests.rs index 8e9a7b37..7ae2d332 100644 --- a/examples/raw_upload/src/tests.rs +++ b/examples/raw_upload/src/tests.rs @@ -11,7 +11,7 @@ const UPLOAD_CONTENTS: &str = "Hey! I'm going to be uploaded. :D Yay!"; fn test_index() { let client = Client::new(super::rocket()).unwrap(); let mut res = client.get("/").dispatch(); - assert_eq!(res.body_string(), Some(super::index().to_string())); + assert_eq!(res.body_string_wait(), Some(super::index().to_string())); } #[test] @@ -28,7 +28,7 @@ fn test_raw_upload() { .dispatch(); assert_eq!(res.status(), Status::Ok); - assert_eq!(res.body_string(), Some(UPLOAD_CONTENTS.len().to_string())); + assert_eq!(res.body_string_wait(), Some(UPLOAD_CONTENTS.len().to_string())); // Ensure we find the body in the /tmp/upload.txt file. let mut file_contents = String::new(); diff --git a/examples/redirect/src/tests.rs b/examples/redirect/src/tests.rs index 51b6deb6..d0c213d1 100644 --- a/examples/redirect/src/tests.rs +++ b/examples/redirect/src/tests.rs @@ -26,5 +26,5 @@ fn test_root() { fn test_login() { let client = client(); let mut r = client.get("/login").dispatch(); - assert_eq!(r.body_string(), Some("Hi! Please log in before continuing.".into())); + assert_eq!(r.body_string_wait(), Some("Hi! Please log in before continuing.".into())); } diff --git a/examples/request_guard/src/main.rs b/examples/request_guard/src/main.rs index 6ff46d76..d1085c84 100644 --- a/examples/request_guard/src/main.rs +++ b/examples/request_guard/src/main.rs @@ -43,7 +43,7 @@ mod test { let mut response = req.dispatch(); let expect = format!("Your request contained {} headers!", headers.len()); - assert_eq!(response.body_string(), Some(expect)); + assert_eq!(response.body_string_wait(), Some(expect)); } #[test] diff --git a/examples/state/src/tests.rs b/examples/state/src/tests.rs index d83beed7..2783ed24 100644 --- a/examples/state/src/tests.rs +++ b/examples/state/src/tests.rs @@ -8,7 +8,7 @@ fn register_hit(client: &Client) { fn get_count(client: &Client) -> usize { let mut response = client.get("/count").dispatch(); - response.body_string().and_then(|s| s.parse().ok()).unwrap() + response.body_string_wait().and_then(|s| s.parse().ok()).unwrap() } #[test] diff --git a/examples/stream/src/tests.rs b/examples/stream/src/tests.rs index 50b29762..28c26c6c 100644 --- a/examples/stream/src/tests.rs +++ b/examples/stream/src/tests.rs @@ -9,7 +9,7 @@ fn test_root() { let mut res = client.get("/").dispatch(); // Check that we have exactly 25,000 'a'. - let res_str = res.body_string().unwrap(); + let res_str = res.body_string_wait().unwrap(); assert_eq!(res_str.len(), 25000); for byte in res_str.as_bytes() { assert_eq!(*byte, b'a'); @@ -26,7 +26,7 @@ fn test_file() { // Get the big file contents, hopefully. let client = Client::new(super::rocket()).unwrap(); let mut res = client.get("/big_file").dispatch(); - assert_eq!(res.body_string(), Some(CONTENTS.into())); + assert_eq!(res.body_string_wait(), Some(CONTENTS.into())); // Delete the 'big_file'. fs::remove_file(super::FILENAME).expect("remove big_file"); diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index 9027cda3..cfcaa2b1 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -26,6 +26,6 @@ mod test { let client = Client::new(rocket()).unwrap(); let mut response = client.get("/").dispatch(); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.body_string(), Some("Hello, world!".into())); + assert_eq!(response.body_string_wait(), Some("Hello, world!".into())); } } diff --git a/examples/tls/src/tests.rs b/examples/tls/src/tests.rs index 80bf4aeb..069157da 100644 --- a/examples/tls/src/tests.rs +++ b/examples/tls/src/tests.rs @@ -5,5 +5,5 @@ fn hello_world() { let rocket = rocket::ignite().mount("/", routes![super::hello]); let client = Client::new(rocket).unwrap(); let mut response = client.get("/").dispatch(); - assert_eq!(response.body_string(), Some("Hello, world!".into())); + assert_eq!(response.body_string_wait(), Some("Hello, world!".into())); } diff --git a/examples/uuid/src/tests.rs b/examples/uuid/src/tests.rs index fa31e31d..adbe231b 100644 --- a/examples/uuid/src/tests.rs +++ b/examples/uuid/src/tests.rs @@ -5,7 +5,7 @@ use rocket::http::Status; fn test(uri: &str, expected: &str) { let client = Client::new(rocket()).unwrap(); let mut res = client.get(uri).dispatch(); - assert_eq!(res.body_string(), Some(expected.into())); + assert_eq!(res.body_string_wait(), Some(expected.into())); } fn test_404(uri: &str) {