9
9
// such invalid requests.
10
10
11
11
use async_trait:: async_trait;
12
+ use bytes:: Bytes ;
12
13
use chrono:: { DateTime , Duration , Utc } ;
13
14
use dropshot:: endpoint;
14
- use dropshot:: test_util:: read_json;
15
15
use dropshot:: test_util:: LogContext ;
16
16
use dropshot:: test_util:: TestContext ;
17
17
use dropshot:: ApiDescription ;
@@ -229,6 +229,7 @@ async fn whoami_request(
229
229
testctx : & TestContext < WhoamiServerState > ,
230
230
) -> Result < WhoamiResponse , ( http:: StatusCode , HttpErrorResponseBody ) > {
231
231
let client_testctx = & testctx. client_testctx ;
232
+
232
233
let mut builder = hyper:: Request :: builder ( )
233
234
. method ( http:: method:: Method :: GET )
234
235
. uri ( client_testctx. url ( "/whoami" ) ) ;
@@ -243,21 +244,27 @@ async fn whoami_request(
243
244
}
244
245
245
246
let request = builder
246
- . body ( dropshot :: Body :: empty ( ) )
247
+ . body ( Bytes :: new ( ) )
247
248
. expect ( "attempted to construct invalid request" ) ;
248
249
249
- let mut response = hyper :: Client :: new ( )
250
- . request ( request)
250
+ let response = reqwest :: Client :: new ( )
251
+ . execute ( request. try_into ( ) . expect ( " request conversion failed" ) )
251
252
. await
252
253
. expect ( "failed to make request" ) ;
253
- if response. status ( ) == http:: StatusCode :: OK {
254
- let whoami: WhoamiResponse = read_json ( & mut response) . await ;
255
- info ! ( & testctx. log, "whoami response" ; "whoami" => ?whoami) ;
256
- Ok ( whoami)
257
- } else {
258
- let error_body: HttpErrorResponseBody = read_json ( & mut response) . await ;
259
- info ! ( & testctx. log, "whoami error" ; "error" => ?error_body) ;
260
- Err ( ( response. status ( ) , error_body) )
254
+
255
+ match response. status ( ) {
256
+ reqwest:: StatusCode :: OK => {
257
+ let whoami = response. json ( ) . await . expect ( "deserialization failed" ) ;
258
+ info ! ( & testctx. log, "whoami response" ; "whoami" => ?whoami) ;
259
+ Ok ( whoami)
260
+ }
261
+
262
+ status => {
263
+ let error_body: HttpErrorResponseBody =
264
+ response. json ( ) . await . expect ( "deserialization failed" ) ;
265
+ info ! ( & testctx. log, "whoami error" ; "error" => ?error_body) ;
266
+ Err ( ( status, error_body) )
267
+ }
261
268
}
262
269
}
263
270
0 commit comments