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

cfg UnixListener tests for unix #3085

Merged
merged 2 commits into from
Dec 21, 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: 19 additions & 3 deletions axum/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -435,6 +440,7 @@ mod tests {
#[derive(Clone, Debug)]
struct UdsConnectInfo;

#[cfg(unix)]
impl Connected<IncomingStream<'_, UnixListener>> for UdsConnectInfo {
fn connect_info(_stream: IncomingStream<'_, UnixListener>) -> Self {
Self
Expand All @@ -458,6 +464,7 @@ mod tests {
serve(tcp_nodelay_listener().await, router.clone())
.await
.unwrap();
#[cfg(unix)]
serve(UnixListener::bind("").unwrap(), router.clone());

serve(
Expand All @@ -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(),
Expand All @@ -485,6 +493,7 @@ mod tests {
.clone()
.into_make_service_with_connect_info::<std::net::SocketAddr>(),
);
#[cfg(unix)]
serve(
UnixListener::bind("").unwrap(),
router.into_make_service_with_connect_info::<UdsConnectInfo>(),
Expand All @@ -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(
Expand All @@ -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(),
Expand All @@ -516,6 +527,7 @@ mod tests {
tcp_nodelay_listener().await,
get(handler).into_make_service_with_connect_info::<std::net::SocketAddr>(),
);
#[cfg(unix)]
serve(
UnixListener::bind("").unwrap(),
get(handler).into_make_service_with_connect_info::<UdsConnectInfo>(),
Expand All @@ -527,20 +539,23 @@ mod tests {
handler.into_service(),
);
serve(tcp_nodelay_listener().await, handler.into_service());
#[cfg(unix)]
serve(UnixListener::bind("").unwrap(), handler.into_service());

serve(
TcpListener::bind(addr).await.unwrap(),
handler.with_state(()),
);
serve(tcp_nodelay_listener().await, handler.with_state(()));
#[cfg(unix)]
serve(UnixListener::bind("").unwrap(), handler.with_state(()));

serve(
TcpListener::bind(addr).await.unwrap(),
handler.into_make_service(),
);
serve(tcp_nodelay_listener().await, handler.into_make_service());
#[cfg(unix)]
serve(UnixListener::bind("").unwrap(), handler.into_make_service());

serve(
Expand All @@ -551,6 +566,7 @@ mod tests {
tcp_nodelay_listener().await,
handler.into_make_service_with_connect_info::<std::net::SocketAddr>(),
);
#[cfg(unix)]
serve(
UnixListener::bind("").unwrap(),
handler.into_make_service_with_connect_info::<UdsConnectInfo>(),
Expand Down