Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aturon committed Feb 21, 2019
1 parent 9fee015 commit 3690951
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use std::ops::{Deref, DerefMut};

use crate::{configuration::Store, Extract, IntoResponse, Request, Response, RouteMatch};

async fn body_to_vec(body: Body) -> Result<Vec<u8>, io::Error> {
pub(crate) async fn body_to_vec(body: Body) -> Result<Vec<u8>, io::Error> {
let mut bytes = Vec::new();
pin_mut!(body);
while let Some(chunk) = await!(body.next()) {
Expand Down
24 changes: 12 additions & 12 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ mod tests {
use futures::{executor::block_on, future::FutureObj};

use super::*;
use crate::{body::Body, middleware::RequestContext, AppData, Response};
use crate::{middleware::RequestContext, AppData, Response, body::body_to_vec};

fn passthrough_middleware<Data: Clone + Send>(
ctx: RequestContext<Data>,
Expand All @@ -351,7 +351,7 @@ mod tests {
let data = Data::default();
let req = http::Request::builder()
.method(method)
.body(Body::empty())
.body(http_service::Body::empty())
.unwrap();

let ctx = RequestContext {
Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {
panic!("Routing of path `{}` failed", path);
};
let body =
block_on(res.into_body().read_to_vec()).expect("Reading body should succeed");
block_on(body_to_vec(res.into_body())).expect("Reading body should succeed");
assert_eq!(&*body, path.as_bytes());
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ mod tests {
panic!("Routing of path `{}` failed", path);
};
let body =
block_on(res.into_body().read_to_vec()).expect("Reading body should succeed");
block_on(body_to_vec(res.into_body())).expect("Reading body should succeed");
assert_eq!(&*body, path.as_bytes());
}
}
Expand All @@ -464,7 +464,7 @@ mod tests {
panic!("Routing of {} `{}` failed", method, path);
};
let body =
block_on(res.into_body().read_to_vec()).expect("Reading body should succeed");
block_on(body_to_vec(res.into_body())).expect("Reading body should succeed");
assert_eq!(&*body, format!("{} {}", path, method).as_bytes());
}
}
Expand Down Expand Up @@ -570,11 +570,11 @@ mod tests {
router.apply_default_config(); // simulating App behavior

let res = block_on(simulate_request(&router, "/", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"foo");

let res = block_on(simulate_request(&router, "/bar", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"bar");
}

Expand All @@ -598,15 +598,15 @@ mod tests {
router.apply_default_config(); // simulating App behavior

let res = block_on(simulate_request(&router, "/", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"foo");

let res = block_on(simulate_request(&router, "/bar", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"bar");

let res = block_on(simulate_request(&router, "/bar/baz", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"baz");
}

Expand All @@ -626,11 +626,11 @@ mod tests {
router.apply_default_config(); // simulating App behavior

let res = block_on(simulate_request(&router, "/", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"foo");

let res = block_on(simulate_request(&router, "/bar", &http::Method::GET)).unwrap();
let body = block_on(res.into_body().read_to_vec()).unwrap();
let body = block_on(body_to_vec(res.into_body())).unwrap();
assert_eq!(&*body, &*b"bar");
}
}

0 comments on commit 3690951

Please sign in to comment.