Use 'body_string_wait' in all example tests.

This commit is contained in:
Jeb Rosen 2019-08-04 15:29:47 -07:00 committed by Sergio Benitez
parent 5e578e9c3b
commit bc404f1f6d
24 changed files with 44 additions and 44 deletions

View File

@ -12,7 +12,7 @@ fn test<H>(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]

View File

@ -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]

View File

@ -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()));
}

View File

@ -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<'_>) {

View File

@ -14,7 +14,7 @@ fn test_login<T>(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)));
}
}

View File

@ -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.");
}
}

View File

@ -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.");
}
}

View File

@ -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) {

View File

@ -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()));
}

View File

@ -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()));
}

View File

@ -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]

View File

@ -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) {

View File

@ -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]

View File

@ -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()));
});
}

View File

@ -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]

View File

@ -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()));
}

View File

@ -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();

View File

@ -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()));
}

View File

@ -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]

View File

@ -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]

View File

@ -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");

View File

@ -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()));
}
}

View File

@ -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()));
}

View File

@ -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) {