From f476b313adac5e3c161dbd321da234e5ef962da8 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 23 Dec 2024 22:21:00 +0100 Subject: [PATCH] Simplify `TestClient` implementation (#3096) --- axum/src/test_helpers/test_client.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/axum/src/test_helpers/test_client.rs b/axum/src/test_helpers/test_client.rs index adab6944..7a177aa5 100644 --- a/axum/src/test_helpers/test_client.rs +++ b/axum/src/test_helpers/test_client.rs @@ -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; @@ -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 { @@ -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 { self.response.chunk().await.unwrap() }