From eca9ab0d5f43b68075259021c15e0173df0117e2 Mon Sep 17 00:00:00 2001 From: 2ndDerivative Date: Thu, 19 Dec 2024 01:59:37 +0100 Subject: [PATCH 1/2] cfg UnixListener tests for unix --- axum/src/serve.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/axum/src/serve.rs b/axum/src/serve.rs index 9a5010c04e..a61664aa20 100644 --- a/axum/src/serve.rs +++ b/axum/src/serve.rs @@ -415,26 +415,32 @@ mod tests { use axum_core::{body::Body, extract::Request}; use http::StatusCode; use hyper_util::rt::TokioIo; + #[cfg(unix)] + use tokio::net::UnixListener; use tokio::{ io::{self, AsyncRead, AsyncWrite}, - net::{TcpListener, UnixListener}, + net::TcpListener, }; - use super::{serve, IncomingStream, Listener}; + #[cfg(unix)] + use super::IncomingStream; + use super::{serve, Listener}; use crate::{ body::to_bytes, - extract::connect_info::Connected, handler::{Handler, HandlerWithoutStateExt}, routing::get, serve::ListenerExt, Router, }; + #[cfg(unix)] + use extract::connect_info::Connected; #[allow(dead_code, unused_must_use)] async fn if_it_compiles_it_works() { #[derive(Clone, Debug)] struct UdsConnectInfo; + #[cfg(unix)] impl Connected> for UdsConnectInfo { fn connect_info(_stream: IncomingStream<'_, UnixListener>) -> Self { Self @@ -458,6 +464,7 @@ mod tests { serve(tcp_nodelay_listener().await, router.clone()) .await .unwrap(); + #[cfg(unix)] serve(UnixListener::bind("").unwrap(), router.clone()); serve( @@ -468,6 +475,7 @@ mod tests { tcp_nodelay_listener().await, router.clone().into_make_service(), ); + #[cfg(unix)] serve( UnixListener::bind("").unwrap(), router.clone().into_make_service(), @@ -485,6 +493,7 @@ mod tests { .clone() .into_make_service_with_connect_info::(), ); + #[cfg(unix)] serve( UnixListener::bind("").unwrap(), router.into_make_service_with_connect_info::(), @@ -493,6 +502,7 @@ mod tests { // method router serve(TcpListener::bind(addr).await.unwrap(), get(handler)); serve(tcp_nodelay_listener().await, get(handler)); + #[cfg(unix)] serve(UnixListener::bind("").unwrap(), get(handler)); serve( @@ -503,6 +513,7 @@ mod tests { tcp_nodelay_listener().await, get(handler).into_make_service(), ); + #[cfg(unix)] serve( UnixListener::bind("").unwrap(), get(handler).into_make_service(), @@ -516,6 +527,7 @@ mod tests { tcp_nodelay_listener().await, get(handler).into_make_service_with_connect_info::(), ); + #[cfg(unix)] serve( UnixListener::bind("").unwrap(), get(handler).into_make_service_with_connect_info::(), @@ -527,6 +539,7 @@ mod tests { handler.into_service(), ); serve(tcp_nodelay_listener().await, handler.into_service()); + #[cfg(unix)] serve(UnixListener::bind("").unwrap(), handler.into_service()); serve( @@ -534,6 +547,7 @@ mod tests { handler.with_state(()), ); serve(tcp_nodelay_listener().await, handler.with_state(())); + #[cfg(unix)] serve(UnixListener::bind("").unwrap(), handler.with_state(())); serve( @@ -541,6 +555,7 @@ mod tests { handler.into_make_service(), ); serve(tcp_nodelay_listener().await, handler.into_make_service()); + #[cfg(unix)] serve(UnixListener::bind("").unwrap(), handler.into_make_service()); serve( @@ -551,6 +566,7 @@ mod tests { tcp_nodelay_listener().await, handler.into_make_service_with_connect_info::(), ); + #[cfg(unix)] serve( UnixListener::bind("").unwrap(), handler.into_make_service_with_connect_info::(), From 34dfdb3036c369389c0dafba86633ea03fb816ce Mon Sep 17 00:00:00 2001 From: 2ndDerivative Date: Fri, 20 Dec 2024 10:11:37 +0100 Subject: [PATCH 2/2] fix missing root crate:: in item path --- axum/src/serve.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axum/src/serve.rs b/axum/src/serve.rs index a61664aa20..0ce0eb605f 100644 --- a/axum/src/serve.rs +++ b/axum/src/serve.rs @@ -425,6 +425,8 @@ mod tests { #[cfg(unix)] use super::IncomingStream; use super::{serve, Listener}; + #[cfg(unix)] + use crate::extract::connect_info::Connected; use crate::{ body::to_bytes, handler::{Handler, HandlerWithoutStateExt}, @@ -432,8 +434,6 @@ mod tests { serve::ListenerExt, Router, }; - #[cfg(unix)] - use extract::connect_info::Connected; #[allow(dead_code, unused_must_use)] async fn if_it_compiles_it_works() {