Skip to content

Commit

Permalink
use "&res.body_string()" instead of "res.take_body().into_string()"
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke-ota committed May 23, 2020
1 parent af3b75f commit f8c41bc
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions tests/wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ async fn wildcard() {
Method::Get,
Url::parse("http://localhost/add_one/3").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"4");
assert_eq!(&res.body_string().await.unwrap(), "4");

let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/add_one/-7").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"-6");
assert_eq!(&res.body_string().await.unwrap(), "-6");
}

#[async_std::test]
Expand Down Expand Up @@ -87,25 +85,22 @@ async fn wild_path() {
Method::Get,
Url::parse("http://localhost/echo/some_path").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"some_path");
assert_eq!(&res.body_string().await.unwrap(), "some_path");

let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/echo/multi/segment/path").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"multi/segment/path");
assert_eq!(&res.body_string().await.unwrap(), "multi/segment/path");

let req = http::Request::new(Method::Get, Url::parse("http://localhost/echo/").unwrap());
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::NotFound);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"");
assert_eq!(&res.body_string().await.unwrap(), "");
}

#[async_std::test]
Expand All @@ -117,19 +112,17 @@ async fn multi_wildcard() {
Method::Get,
Url::parse("http://localhost/add_two/1/2/").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"3");
assert_eq!(&res.body_string().await.unwrap(), "3");

let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/add_two/-1/2/").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), 200);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"1");
assert_eq!(&res.body_string().await.unwrap(), "1");

let req = http::Request::new(
Method::Get,
Expand All @@ -148,19 +141,17 @@ async fn wild_last_segment() {
Method::Get,
Url::parse("http://localhost/echo/one/two").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"one");
assert_eq!(&res.body_string().await.unwrap(), "one");

let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/echo/one/two/three/four").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"one");
assert_eq!(&res.body_string().await.unwrap(), "one");
}

#[async_std::test]
Expand Down Expand Up @@ -212,19 +203,17 @@ async fn nameless_internal_wildcard() {
Method::Get,
Url::parse("http://localhost/echo/one/two").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"two");
assert_eq!(&res.body_string().await.unwrap(), "two");

let req = http::Request::new(
Method::Get,
Url::parse("http://localhost/echo/one/two").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"two");
assert_eq!(&res.body_string().await.unwrap(), "two");
}

#[async_std::test]
Expand All @@ -236,8 +225,7 @@ async fn nameless_internal_wildcard2() {
Method::Get,
Url::parse("http://localhost/echo/one/two").unwrap(),
);
let mut res: http::Response = app.respond(req).await.unwrap();
let res: http::Response = app.respond(req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);
let body: String = res.take_body().into_string().await.unwrap();
assert_eq!(body.as_bytes(), b"one");
assert_eq!(&res.body_string().await.unwrap(), "one");
}

0 comments on commit f8c41bc

Please sign in to comment.