Fix a minor compilation error, possibly caused by rust-lang/rust#64292.

This commit is contained in:
Jeb Rosen 2019-09-10 19:16:48 -07:00
parent b0d6d625fe
commit bdbf80f2da
17 changed files with 80 additions and 56 deletions

View File

@ -26,13 +26,16 @@ async fn test_ranking() {
let mut response = client.get("/0").dispatch().await; let mut response = client.get("/0").dispatch().await;
assert_eq!(response.body_string().await.unwrap(), "0"); assert_eq!(response.body_string().await.unwrap(), "0");
let mut response = client.get(format!("/{}", 1 << 8)).dispatch().await; let request = client.get(format!("/{}", 1 << 8));
let mut response = request.dispatch().await;
assert_eq!(response.body_string().await.unwrap(), "1"); assert_eq!(response.body_string().await.unwrap(), "1");
let mut response = client.get(format!("/{}", 1 << 16)).dispatch().await; let request = client.get(format!("/{}", 1 << 16));
let mut response = request.dispatch().await;
assert_eq!(response.body_string().await.unwrap(), "2"); assert_eq!(response.body_string().await.unwrap(), "2");
let mut response = client.get(format!("/{}", 1u64 << 32)).dispatch().await; let request = client.get(format!("/{}", 1u64 << 32));
let mut response = request.dispatch().await;
assert_eq!(response.body_string().await.unwrap(), "3"); assert_eq!(response.body_string().await.unwrap(), "3");
} }

View File

@ -103,26 +103,28 @@ async fn test_full_route() {
let response = client.post(&uri).body(simple).dispatch().await; let response = client.post(&uri).body(simple).dispatch().await;
assert_eq!(response.status(), Status::NotFound); assert_eq!(response.status(), Status::NotFound);
let response = client.post(format!("/1{}", uri)).body(simple).dispatch().await; let request = client.post(format!("/1{}", uri)).body(simple);
let response = request.dispatch().await;
assert_eq!(response.status(), Status::NotFound); assert_eq!(response.status(), Status::NotFound);
let mut response = client let request = client
.post(format!("/1{}", uri)) .post(format!("/1{}", uri))
.header(ContentType::JSON) .header(ContentType::JSON)
.body(simple) .body(simple);
.dispatch().await; let mut response = request.dispatch().await;
assert_eq!(response.body_string().await.unwrap(), format!("({}, {}, {}, {}, {}, {}) ({})", assert_eq!(response.body_string().await.unwrap(), format!("({}, {}, {}, {}, {}, {}) ({})",
sky, name, "A A", "inside", path, simple, expected_uri)); sky, name, "A A", "inside", path, simple, expected_uri));
let response = client.post(format!("/2{}", uri)).body(simple).dispatch().await; let request = client.post(format!("/2{}", uri)).body(simple);
let response = request.dispatch().await;
assert_eq!(response.status(), Status::NotFound); assert_eq!(response.status(), Status::NotFound);
let mut response = client let request = client
.post(format!("/2{}", uri)) .post(format!("/2{}", uri))
.header(ContentType::JSON) .header(ContentType::JSON)
.body(simple) .body(simple);
.dispatch().await; let mut response = request.dispatch().await;
assert_eq!(response.body_string().await.unwrap(), format!("({}, {}, {}, {}, {}, {}) ({})", assert_eq!(response.body_string().await.unwrap(), format!("({}, {}, {}, {}, {}, {}) ({})",
sky, name, "A A", "inside", path, simple, expected_uri)); sky, name, "A A", "inside", path, simple, expected_uri));

View File

@ -171,7 +171,8 @@ impl Data {
pub fn stream_to_file<P: AsRef<Path> + Send + Unpin + 'static>(self, path: P) -> impl Future<Output = io::Result<u64>> { pub fn stream_to_file<P: AsRef<Path> + Send + Unpin + 'static>(self, path: P) -> impl Future<Output = io::Result<u64>> {
Box::pin(async move { Box::pin(async move {
let mut file = async_std::fs::File::create(path).await?; let mut file = async_std::fs::File::create(path).await?;
self.stream_to(&mut file).await let streaming = self.stream_to(&mut file);
streaming.await
}) })
} }

View File

@ -348,7 +348,8 @@ impl<'c> LocalRequest<'c> {
#[inline(always)] #[inline(always)]
pub async fn dispatch(mut self) -> LocalResponse<'c> { pub async fn dispatch(mut self) -> LocalResponse<'c> {
let r = self.long_lived_request(); let r = self.long_lived_request();
LocalRequest::_dispatch(self.client, r, self.request, &self.uri, self.data).await let dispatching = LocalRequest::_dispatch(self.client, r, self.request, &self.uri, self.data);
dispatching.await
} }
/// Dispatches the request, returning the response. /// Dispatches the request, returning the response.

View File

@ -22,10 +22,10 @@ mod tests {
async fn check_decoding(raw: &str, decoded: &str) { async fn check_decoding(raw: &str, decoded: &str) {
let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap(); let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap();
let mut response = client.post("/") let request = client.post("/")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("form_data={}", raw)) .body(format!("form_data={}", raw));
.dispatch().await; let mut response = request.dispatch().await;
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
assert_eq!(Some(decoded.to_string()), response.body_string().await); assert_eq!(Some(decoded.to_string()), response.body_string().await);

View File

@ -47,7 +47,8 @@ mod tests {
"/static", "/point/static"] "/static", "/point/static"]
{ {
let path = "this/is/the/path/we/want"; let path = "this/is/the/path/we/want";
let mut response = client.get(format!("{}/{}", prefix, path)).dispatch().await; let request = client.get(format!("{}/{}", prefix, path));
let mut response = request.dispatch().await;
assert_eq!(response.body_string().await, Some(path.into())); assert_eq!(response.body_string().await, Some(path.into()));
} }
} }

View File

@ -34,18 +34,18 @@ mod strict_and_lenient_forms_tests {
#[rocket::async_test] #[rocket::async_test]
async fn test_strict_form() { async fn test_strict_form() {
let client = client(); let client = client();
let mut response = client.post("/strict") let request = client.post("/strict")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("field={}", FIELD_VALUE)) .body(format!("field={}", FIELD_VALUE));
.dispatch().await; let mut response = request.dispatch().await;
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string().await, Some(FIELD_VALUE.into())); assert_eq!(response.body_string().await, Some(FIELD_VALUE.into()));
let response = client.post("/strict") let request = client.post("/strict")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("field={}&extra=whoops", FIELD_VALUE)) .body(format!("field={}&extra=whoops", FIELD_VALUE));
.dispatch().await; let response = request.dispatch().await;
assert_eq!(response.status(), Status::UnprocessableEntity); assert_eq!(response.status(), Status::UnprocessableEntity);
} }
@ -53,18 +53,18 @@ mod strict_and_lenient_forms_tests {
#[rocket::async_test] #[rocket::async_test]
async fn test_lenient_form() { async fn test_lenient_form() {
let client = client(); let client = client();
let mut response = client.post("/lenient") let request = client.post("/lenient")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("field={}", FIELD_VALUE)) .body(format!("field={}", FIELD_VALUE));
.dispatch().await; let mut response = request.dispatch().await;
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string().await, Some(FIELD_VALUE.into())); assert_eq!(response.body_string().await, Some(FIELD_VALUE.into()));
let mut response = client.post("/lenient") let request = client.post("/lenient")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("field={}&extra=whoops", FIELD_VALUE)) .body(format!("field={}&extra=whoops", FIELD_VALUE));
.dispatch().await; let mut response = request.dispatch().await;
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string().await, Some(FIELD_VALUE.into())); assert_eq!(response.body_string().await, Some(FIELD_VALUE.into()));

View File

@ -52,7 +52,8 @@ mod tests {
async fn uri_percent_encoding_get() { async fn uri_percent_encoding_get() {
let client = Client::new(rocket()).unwrap(); let client = Client::new(rocket()).unwrap();
let name = Uri::percent_encode(NAME); let name = Uri::percent_encode(NAME);
let mut response = client.get(format!("/hello/{}", name)).dispatch().await; let request = client.get(format!("/hello/{}", name));
let mut response = request.dispatch().await;
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string().await.unwrap(), format!("Hello, {}!", NAME)); assert_eq!(response.body_string().await.unwrap(), format!("Hello, {}!", NAME));
} }

View File

@ -7,7 +7,8 @@ async fn test(uri: &str, status: Status, body: String) {
.register(catchers![super::not_found]); .register(catchers![super::not_found]);
let client = Client::new(rocket).unwrap(); let client = Client::new(rocket).unwrap();
let mut response = client.get(uri).dispatch().await; let request = client.get(uri);
let mut response = request.dispatch().await;
assert_eq!(response.status(), status); assert_eq!(response.status(), status);
assert_eq!(response.body_string().await, Some(body)); assert_eq!(response.body_string().await, Some(body));
} }
@ -16,7 +17,8 @@ async fn test(uri: &str, status: Status, body: String) {
async fn test_hello() { async fn test_hello() {
let (name, age) = ("Arthur", 42); let (name, age) = ("Arthur", 42);
let uri = format!("/hello/{}/{}", name, age); let uri = format!("/hello/{}/{}", name, age);
test(&uri, Status::Ok, format!("Hello, {} year old named {}!", age, name)).await; let expected = format!("Hello, {} year old named {}!", age, name);
test(&uri, Status::Ok, expected).await;
} }
#[rocket::async_test] #[rocket::async_test]

View File

@ -18,8 +18,9 @@ async fn test_404(uri: &'static str) {
#[rocket::async_test] #[rocket::async_test]
async fn test_hello() { async fn test_hello() {
for &(name, age) in &[("Mike", 22), ("Michael", 80), ("A", 0), ("a", 127)] { for &(name, age) in &[("Mike", 22), ("Michael", 80), ("A", 0), ("a", 127)] {
test(format!("/hello/{}/{}", name, age), let uri = format!("/hello/{}/{}", name, age);
format!("Hello, {} year old named {}!", age, name)).await; let expected = format!("Hello, {} year old named {}!", age, name);
test(uri, expected).await;
} }
} }
@ -33,6 +34,7 @@ async fn test_failing_hello() {
#[rocket::async_test] #[rocket::async_test]
async fn test_hi() { async fn test_hi() {
for name in &["Mike", "A", "123", "hi", "c"] { for name in &["Mike", "A", "123", "hi", "c"] {
test(format!("/hello/{}", name), name.to_string()).await; let uri = format!("/hello/{}", name);
test(uri, name.to_string()).await;
} }
} }

View File

@ -51,7 +51,8 @@ fn upload<'r>(req: &'r Request, data: Data) -> HandlerFuture<'r> {
let file = File::create(env::temp_dir().join("upload.txt")).await; let file = File::create(env::temp_dir().join("upload.txt")).await;
if let Ok(file) = file { if let Ok(file) = file {
if let Ok(n) = data.stream_to(file).await { if let Ok(n) = data.stream_to(file).await {
return Outcome::from(req, format!("OK: {} bytes uploaded.", n)).await; let response = format!("OK: {} bytes uploaded.", n);
return Outcome::from(req, response).await;
} }
println!(" => Failed copying."); println!(" => Failed copying.");
@ -92,7 +93,8 @@ impl Handler for CustomHandler {
.or_forward(data); .or_forward(data);
let id = try_outcome!(id_outcome); let id = try_outcome!(id_outcome);
Outcome::from(req, format!("{} - {}", self_data, id)).await let response = format!("{} - {}", self_data, id);
Outcome::from(req, response).await
}) })
} }
} }

View File

@ -5,7 +5,8 @@ use rocket::http::{ContentType, Status};
fn test(uri: &str, content_type: ContentType, status: Status, body: String) { fn test(uri: &str, content_type: ContentType, status: Status, body: String) {
rocket::async_test(async move { rocket::async_test(async move {
let client = Client::new(rocket()).unwrap(); let client = Client::new(rocket()).unwrap();
let mut response = client.get(uri).header(content_type).dispatch().await; let request = client.get(uri).header(content_type);
let mut response = request.dispatch().await;
assert_eq!(response.status(), status); assert_eq!(response.status(), status);
assert_eq!(response.body_string().await, Some(body)); assert_eq!(response.body_string().await, Some(body));
}) })

View File

@ -25,7 +25,8 @@ async fn upload_paste(client: &Client, body: &str) -> String {
} }
async fn download_paste(client: &Client, id: &str) -> String { async fn download_paste(client: &Client, id: &str) -> String {
let mut response = client.get(format!("/{}", id)).dispatch().await; let request = client.get(format!("/{}", id));
let mut response = request.dispatch().await;
assert_eq!(response.status(), Status::Ok); assert_eq!(response.status(), Status::Ok);
response.body_string().await.unwrap() response.body_string().await.unwrap()
} }

View File

@ -5,8 +5,9 @@ use rocket::http::Status;
macro_rules! run_test { macro_rules! run_test {
($query:expr, |$response:ident| $body:expr) => ({ ($query:expr, |$response:ident| $body:expr) => ({
let client = Client::new(rocket()).unwrap(); let client = Client::new(rocket()).unwrap();
let request = client.get(format!("/hello{}", $query));
#[allow(unused_mut)] #[allow(unused_mut)]
let mut $response = client.get(format!("/hello{}", $query)).dispatch().await; let mut $response = request.dispatch().await;
$body $body
}) })
} }

View File

@ -3,15 +3,16 @@ use rocket::local::Client;
async fn test(uri: String, expected: String) { async fn test(uri: String, expected: String) {
let rocket = rocket::ignite().mount("/", routes![super::hello, super::hi]); let rocket = rocket::ignite().mount("/", routes![super::hello, super::hi]);
let client = Client::new(rocket).unwrap(); let client = Client::new(rocket).unwrap();
let mut response = client.get(&uri).dispatch().await; let mut response = client.get(uri).dispatch().await;
assert_eq!(response.body_string().await, Some(expected)); assert_eq!(response.body_string().await, Some(expected));
} }
#[rocket::async_test] #[rocket::async_test]
async fn test_hello() { async fn test_hello() {
for &(name, age) in &[("Mike", 22), ("Michael", 80), ("A", 0), ("a", 127)] { for &(name, age) in &[("Mike", 22), ("Michael", 80), ("A", 0), ("a", 127)] {
test(format!("/hello/{}/{}", name, age), let uri = format!("/hello/{}/{}", name, age);
format!("Hello, {} year old named {}!", age, name)).await; let expected = format!("Hello, {} year old named {}!", age, name);
test(uri, expected).await;
} }
} }
@ -19,13 +20,15 @@ async fn test_hello() {
async fn test_failing_hello_hi() { async fn test_failing_hello_hi() {
// Invalid integers. // Invalid integers.
for &(name, age) in &[("Mike", 1000), ("Michael", 128), ("A", -800), ("a", -200)] { for &(name, age) in &[("Mike", 1000), ("Michael", 128), ("A", -800), ("a", -200)] {
test(format!("/hello/{}/{}", name, age), let uri = format!("/hello/{}/{}", name, age);
format!("Hi {}! Your age ({}) is kind of funky.", name, age)).await; let expected = format!("Hi {}! Your age ({}) is kind of funky.", name, age);
test(uri, expected).await;
} }
// Non-integers. // Non-integers.
for &(name, age) in &[("Mike", "!"), ("Michael", "hi"), ("A", "blah"), ("a", "0-1")] { for &(name, age) in &[("Mike", "!"), ("Michael", "hi"), ("A", "blah"), ("a", "0-1")] {
test(format!("/hello/{}/{}", name, age), let uri = format!("/hello/{}/{}", name, age);
format!("Hi {}! Your age ({}) is kind of funky.", name, age)).await; let expected = format!("Hi {}! Your age ({}) is kind of funky.", name, age);
test(uri, expected).await;
} }
} }

View File

@ -14,10 +14,10 @@ fn user_id_cookie(response: &Response<'_>) -> Option<Cookie<'static>> {
} }
async fn login(client: &Client, user: &str, pass: &str) -> Option<Cookie<'static>> { async fn login(client: &Client, user: &str, pass: &str) -> Option<Cookie<'static>> {
let response = client.post("/login") let request = client.post("/login")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("username={}&password={}", user, pass)) .body(format!("username={}&password={}", user, pass));
.dispatch().await; let response = request.dispatch().await;
user_id_cookie(&response) user_id_cookie(&response)
} }

View File

@ -49,7 +49,8 @@ fn test_insertion_deletion() {
// Issue a request to delete the task. // Issue a request to delete the task.
let id = new_tasks[0].id.unwrap(); let id = new_tasks[0].id.unwrap();
client.delete(format!("/todo/{}", id)).dispatch().await; let request = client.delete(format!("/todo/{}", id));
request.dispatch().await;
// Ensure it's gone. // Ensure it's gone.
let final_tasks = Task::all(&conn); let final_tasks = Task::all(&conn);
@ -73,11 +74,13 @@ fn test_toggle() {
assert_eq!(task.completed, false); assert_eq!(task.completed, false);
// Issue a request to toggle the task; ensure it is completed. // Issue a request to toggle the task; ensure it is completed.
client.put(format!("/todo/{}", task.id.unwrap())).dispatch().await; let request = client.put(format!("/todo/{}", task.id.unwrap()));
request.dispatch().await;
assert_eq!(Task::all(&conn)[0].completed, true); assert_eq!(Task::all(&conn)[0].completed, true);
// Issue a request to toggle the task; ensure it's not completed again. // Issue a request to toggle the task; ensure it's not completed again.
client.put(format!("/todo/{}", task.id.unwrap())).dispatch().await; let request = client.put(format!("/todo/{}", task.id.unwrap()));
request.dispatch().await;
assert_eq!(Task::all(&conn)[0].completed, false); assert_eq!(Task::all(&conn)[0].completed, false);
}) })
} }
@ -94,10 +97,10 @@ fn test_many_insertions() {
for i in 0..ITER { for i in 0..ITER {
// Issue a request to insert a new task with a random description. // Issue a request to insert a new task with a random description.
let desc: String = thread_rng().sample_iter(&Alphanumeric).take(12).collect(); let desc: String = thread_rng().sample_iter(&Alphanumeric).take(12).collect();
client.post("/todo") let request = client.post("/todo")
.header(ContentType::Form) .header(ContentType::Form)
.body(format!("description={}", desc)) .body(format!("description={}", desc));
.dispatch().await; request.dispatch().await;
// Record the description we choose for this iteration. // Record the description we choose for this iteration.
descs.insert(0, desc); descs.insert(0, desc);