Skip to content

Commit

Permalink
another client
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl committed Sep 14, 2024
1 parent 355b03f commit b791d7f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions nexus/tests/integration_tests/authn_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// such invalid requests.

use async_trait::async_trait;
use bytes::Bytes;
use chrono::{DateTime, Duration, Utc};
use dropshot::endpoint;
use dropshot::test_util::read_json;
use dropshot::test_util::LogContext;
use dropshot::test_util::TestContext;
use dropshot::ApiDescription;
Expand Down Expand Up @@ -229,6 +229,7 @@ async fn whoami_request(
testctx: &TestContext<WhoamiServerState>,
) -> Result<WhoamiResponse, (http::StatusCode, HttpErrorResponseBody)> {
let client_testctx = &testctx.client_testctx;

let mut builder = hyper::Request::builder()
.method(http::method::Method::GET)
.uri(client_testctx.url("/whoami"));
Expand All @@ -243,21 +244,27 @@ async fn whoami_request(
}

let request = builder
.body(dropshot::Body::empty())
.body(Bytes::new())
.expect("attempted to construct invalid request");

let mut response = hyper::Client::new()
.request(request)
let response = reqwest::Client::new()
.execute(request.try_into().expect("request conversion failed"))
.await
.expect("failed to make request");
if response.status() == http::StatusCode::OK {
let whoami: WhoamiResponse = read_json(&mut response).await;
info!(&testctx.log, "whoami response"; "whoami" => ?whoami);
Ok(whoami)
} else {
let error_body: HttpErrorResponseBody = read_json(&mut response).await;
info!(&testctx.log, "whoami error"; "error" => ?error_body);
Err((response.status(), error_body))

match response.status() {
reqwest::StatusCode::OK => {
let whoami = response.json().await.expect("deserialization failed");
info!(&testctx.log, "whoami response"; "whoami" => ?whoami);
Ok(whoami)
}

status => {
let error_body: HttpErrorResponseBody =
response.json().await.expect("deserialization failed");
info!(&testctx.log, "whoami error"; "error" => ?error_body);
Err((status, error_body))
}
}
}

Expand Down

0 comments on commit b791d7f

Please sign in to comment.