Skip to content

Commit cb247aa

Browse files
committed
change read_to_string() to into_string()
I use 'resp.take_body().read_to_string(&mut foo)' to get body as String type. But, 'resp.take_body().into_string()' is more intuitive. So, exchange method.
1 parent ed05053 commit cb247aa

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

tests/response.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use async_std::io::prelude::*;
21
use tide::*;
32

43
#[async_std::test]
54
async fn test_status() {
65
let mut resp = Response::new(StatusCode::NotFound).body_string("foo".to_string());
76
assert_eq!(resp.status(), StatusCode::NotFound);
87

9-
let mut foo = String::new();
10-
let _bytes = resp.take_body().read_to_string(&mut foo).await;
8+
let foo = resp.take_body().into_string().await.unwrap();
119
assert_eq!(foo.as_bytes(), b"foo");
1210
}
1311

@@ -26,8 +24,7 @@ async fn byte_vec_content_type() {
2624
}
2725
assert_eq!(header_values[0], "application/octet-stream");
2826

29-
let mut foo = String::new();
30-
let _bytes = resp.take_body().read_to_string(&mut foo).await;
27+
let foo = resp.take_body().into_string().await.unwrap();
3128
assert_eq!(foo.as_bytes(), b"foo");
3229
}
3330

@@ -45,8 +42,7 @@ async fn string_content_type() {
4542
}
4643
assert_eq!(header_values[0], "text/plain; charset=utf-8");
4744

48-
let mut foo = String::new();
49-
let _bytes = resp.take_body().read_to_string(&mut foo).await;
45+
let foo = resp.take_body().into_string().await.unwrap();
5046
assert_eq!(foo.as_bytes(), b"foo");
5147
}
5248

@@ -74,8 +70,7 @@ async fn json_content_type() {
7470
let mut resp: http::Response = app.respond(req).await.unwrap();
7571
assert_eq!(resp.status(), StatusCode::InternalServerError);
7672

77-
let mut body = String::new();
78-
let _bytes = resp.take_body().read_to_string(&mut body).await;
73+
let body = resp.take_body().into_string().await.unwrap();
7974
assert_eq!(body.as_bytes(), b"");
8075

8176
let mut map = BTreeMap::new();
@@ -86,7 +81,6 @@ async fn json_content_type() {
8681
let mut resp = Response::new(StatusCode::Ok).body_json(&map).unwrap();
8782
assert_eq!(resp.status(), StatusCode::Ok);
8883

89-
let mut body = String::new();
90-
let _bytes = resp.take_body().read_to_string(&mut body).await;
84+
let body = resp.take_body().into_string().await.unwrap();
9185
assert_eq!(body.as_bytes(), br##"{"a":2,"b":4,"c":6}"##);
9286
}

0 commit comments

Comments
 (0)