From 8af2f27877f2a0e0041fd1930aff9b30e766eb34 Mon Sep 17 00:00:00 2001 From: Niclas Klugmann Date: Sat, 21 Dec 2024 16:48:33 +0100 Subject: [PATCH] cfg UnixListener tests for unix (#3085) --- 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 9a5010c0..0ce0eb60 100644 --- a/axum/src/serve.rs +++ b/axum/src/serve.rs @@ -415,15 +415,20 @@ 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}; + #[cfg(unix)] + use crate::extract::connect_info::Connected; use crate::{ body::to_bytes, - extract::connect_info::Connected, handler::{Handler, HandlerWithoutStateExt}, routing::get, serve::ListenerExt, @@ -435,6 +440,7 @@ mod tests { #[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::(),