1
- use async_std:: io:: prelude:: * ;
2
1
use tide:: * ;
3
2
4
3
#[ async_std:: test]
5
4
async fn test_status ( ) {
6
5
let mut resp = Response :: new ( StatusCode :: NotFound ) . body_string ( "foo" . to_string ( ) ) ;
7
6
assert_eq ! ( resp. status( ) , StatusCode :: NotFound ) ;
8
7
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 ( ) ;
11
9
assert_eq ! ( foo. as_bytes( ) , b"foo" ) ;
12
10
}
13
11
@@ -26,8 +24,7 @@ async fn byte_vec_content_type() {
26
24
}
27
25
assert_eq ! ( header_values[ 0 ] , "application/octet-stream" ) ;
28
26
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 ( ) ;
31
28
assert_eq ! ( foo. as_bytes( ) , b"foo" ) ;
32
29
}
33
30
@@ -45,8 +42,7 @@ async fn string_content_type() {
45
42
}
46
43
assert_eq ! ( header_values[ 0 ] , "text/plain; charset=utf-8" ) ;
47
44
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 ( ) ;
50
46
assert_eq ! ( foo. as_bytes( ) , b"foo" ) ;
51
47
}
52
48
@@ -74,8 +70,7 @@ async fn json_content_type() {
74
70
let mut resp: http:: Response = app. respond ( req) . await . unwrap ( ) ;
75
71
assert_eq ! ( resp. status( ) , StatusCode :: InternalServerError ) ;
76
72
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 ( ) ;
79
74
assert_eq ! ( body. as_bytes( ) , b"" ) ;
80
75
81
76
let mut map = BTreeMap :: new ( ) ;
@@ -86,7 +81,6 @@ async fn json_content_type() {
86
81
let mut resp = Response :: new ( StatusCode :: Ok ) . body_json ( & map) . unwrap ( ) ;
87
82
assert_eq ! ( resp. status( ) , StatusCode :: Ok ) ;
88
83
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 ( ) ;
91
85
assert_eq ! ( body. as_bytes( ) , br##"{"a":2,"b":4,"c":6}"## ) ;
92
86
}
0 commit comments