Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify TestClient implementation #3096

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions axum/src/test_helpers/test_client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::{serve, Request, Response};
use bytes::Bytes;
use futures_util::future::BoxFuture;
use http::{
header::{HeaderName, HeaderValue},
StatusCode,
};
use http::header::{HeaderName, HeaderValue};
use std::ops::Deref;
use std::{convert::Infallible, future::IntoFuture, net::SocketAddr};
use tokio::net::TcpListener;
use tower::make::Shared;
Expand Down Expand Up @@ -144,6 +142,14 @@ pub(crate) struct TestResponse {
response: reqwest::Response,
}

impl Deref for TestResponse {
type Target = reqwest::Response;

fn deref(&self) -> &Self::Target {
&self.response
}
}

impl TestResponse {
#[allow(dead_code)]
pub(crate) async fn bytes(self) -> Bytes {
Expand All @@ -162,14 +168,6 @@ impl TestResponse {
self.response.json().await.unwrap()
}

pub(crate) fn status(&self) -> StatusCode {
StatusCode::from_u16(self.response.status().as_u16()).unwrap()
}

pub(crate) fn headers(&self) -> http::HeaderMap {
self.response.headers().clone()
}

pub(crate) async fn chunk(&mut self) -> Option<Bytes> {
self.response.chunk().await.unwrap()
}
Expand Down