Skip to content

Commit f476b31

Browse files
authored
Simplify TestClient implementation (#3096)
1 parent 8af2f27 commit f476b31

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

axum/src/test_helpers/test_client.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use super::{serve, Request, Response};
22
use bytes::Bytes;
33
use futures_util::future::BoxFuture;
4-
use http::{
5-
header::{HeaderName, HeaderValue},
6-
StatusCode,
7-
};
4+
use http::header::{HeaderName, HeaderValue};
5+
use std::ops::Deref;
86
use std::{convert::Infallible, future::IntoFuture, net::SocketAddr};
97
use tokio::net::TcpListener;
108
use tower::make::Shared;
@@ -144,6 +142,14 @@ pub(crate) struct TestResponse {
144142
response: reqwest::Response,
145143
}
146144

145+
impl Deref for TestResponse {
146+
type Target = reqwest::Response;
147+
148+
fn deref(&self) -> &Self::Target {
149+
&self.response
150+
}
151+
}
152+
147153
impl TestResponse {
148154
#[allow(dead_code)]
149155
pub(crate) async fn bytes(self) -> Bytes {
@@ -162,14 +168,6 @@ impl TestResponse {
162168
self.response.json().await.unwrap()
163169
}
164170

165-
pub(crate) fn status(&self) -> StatusCode {
166-
StatusCode::from_u16(self.response.status().as_u16()).unwrap()
167-
}
168-
169-
pub(crate) fn headers(&self) -> http::HeaderMap {
170-
self.response.headers().clone()
171-
}
172-
173171
pub(crate) async fn chunk(&mut self) -> Option<Bytes> {
174172
self.response.chunk().await.unwrap()
175173
}

0 commit comments

Comments
 (0)