mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-01 08:56:15 +01:00
cfg UnixListener tests for unix (#3085)
This commit is contained in:
parent
9cd5cc4fc1
commit
8af2f27877
1 changed files with 19 additions and 3 deletions
|
@ -415,15 +415,20 @@ mod tests {
|
||||||
use axum_core::{body::Body, extract::Request};
|
use axum_core::{body::Body, extract::Request};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use hyper_util::rt::TokioIo;
|
use hyper_util::rt::TokioIo;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use tokio::net::UnixListener;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{self, AsyncRead, AsyncWrite},
|
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::{
|
use crate::{
|
||||||
body::to_bytes,
|
body::to_bytes,
|
||||||
extract::connect_info::Connected,
|
|
||||||
handler::{Handler, HandlerWithoutStateExt},
|
handler::{Handler, HandlerWithoutStateExt},
|
||||||
routing::get,
|
routing::get,
|
||||||
serve::ListenerExt,
|
serve::ListenerExt,
|
||||||
|
@ -435,6 +440,7 @@ mod tests {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct UdsConnectInfo;
|
struct UdsConnectInfo;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
impl Connected<IncomingStream<'_, UnixListener>> for UdsConnectInfo {
|
impl Connected<IncomingStream<'_, UnixListener>> for UdsConnectInfo {
|
||||||
fn connect_info(_stream: IncomingStream<'_, UnixListener>) -> Self {
|
fn connect_info(_stream: IncomingStream<'_, UnixListener>) -> Self {
|
||||||
Self
|
Self
|
||||||
|
@ -458,6 +464,7 @@ mod tests {
|
||||||
serve(tcp_nodelay_listener().await, router.clone())
|
serve(tcp_nodelay_listener().await, router.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
#[cfg(unix)]
|
||||||
serve(UnixListener::bind("").unwrap(), router.clone());
|
serve(UnixListener::bind("").unwrap(), router.clone());
|
||||||
|
|
||||||
serve(
|
serve(
|
||||||
|
@ -468,6 +475,7 @@ mod tests {
|
||||||
tcp_nodelay_listener().await,
|
tcp_nodelay_listener().await,
|
||||||
router.clone().into_make_service(),
|
router.clone().into_make_service(),
|
||||||
);
|
);
|
||||||
|
#[cfg(unix)]
|
||||||
serve(
|
serve(
|
||||||
UnixListener::bind("").unwrap(),
|
UnixListener::bind("").unwrap(),
|
||||||
router.clone().into_make_service(),
|
router.clone().into_make_service(),
|
||||||
|
@ -485,6 +493,7 @@ mod tests {
|
||||||
.clone()
|
.clone()
|
||||||
.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
||||||
);
|
);
|
||||||
|
#[cfg(unix)]
|
||||||
serve(
|
serve(
|
||||||
UnixListener::bind("").unwrap(),
|
UnixListener::bind("").unwrap(),
|
||||||
router.into_make_service_with_connect_info::<UdsConnectInfo>(),
|
router.into_make_service_with_connect_info::<UdsConnectInfo>(),
|
||||||
|
@ -493,6 +502,7 @@ mod tests {
|
||||||
// method router
|
// method router
|
||||||
serve(TcpListener::bind(addr).await.unwrap(), get(handler));
|
serve(TcpListener::bind(addr).await.unwrap(), get(handler));
|
||||||
serve(tcp_nodelay_listener().await, get(handler));
|
serve(tcp_nodelay_listener().await, get(handler));
|
||||||
|
#[cfg(unix)]
|
||||||
serve(UnixListener::bind("").unwrap(), get(handler));
|
serve(UnixListener::bind("").unwrap(), get(handler));
|
||||||
|
|
||||||
serve(
|
serve(
|
||||||
|
@ -503,6 +513,7 @@ mod tests {
|
||||||
tcp_nodelay_listener().await,
|
tcp_nodelay_listener().await,
|
||||||
get(handler).into_make_service(),
|
get(handler).into_make_service(),
|
||||||
);
|
);
|
||||||
|
#[cfg(unix)]
|
||||||
serve(
|
serve(
|
||||||
UnixListener::bind("").unwrap(),
|
UnixListener::bind("").unwrap(),
|
||||||
get(handler).into_make_service(),
|
get(handler).into_make_service(),
|
||||||
|
@ -516,6 +527,7 @@ mod tests {
|
||||||
tcp_nodelay_listener().await,
|
tcp_nodelay_listener().await,
|
||||||
get(handler).into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
get(handler).into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
||||||
);
|
);
|
||||||
|
#[cfg(unix)]
|
||||||
serve(
|
serve(
|
||||||
UnixListener::bind("").unwrap(),
|
UnixListener::bind("").unwrap(),
|
||||||
get(handler).into_make_service_with_connect_info::<UdsConnectInfo>(),
|
get(handler).into_make_service_with_connect_info::<UdsConnectInfo>(),
|
||||||
|
@ -527,6 +539,7 @@ mod tests {
|
||||||
handler.into_service(),
|
handler.into_service(),
|
||||||
);
|
);
|
||||||
serve(tcp_nodelay_listener().await, handler.into_service());
|
serve(tcp_nodelay_listener().await, handler.into_service());
|
||||||
|
#[cfg(unix)]
|
||||||
serve(UnixListener::bind("").unwrap(), handler.into_service());
|
serve(UnixListener::bind("").unwrap(), handler.into_service());
|
||||||
|
|
||||||
serve(
|
serve(
|
||||||
|
@ -534,6 +547,7 @@ mod tests {
|
||||||
handler.with_state(()),
|
handler.with_state(()),
|
||||||
);
|
);
|
||||||
serve(tcp_nodelay_listener().await, handler.with_state(()));
|
serve(tcp_nodelay_listener().await, handler.with_state(()));
|
||||||
|
#[cfg(unix)]
|
||||||
serve(UnixListener::bind("").unwrap(), handler.with_state(()));
|
serve(UnixListener::bind("").unwrap(), handler.with_state(()));
|
||||||
|
|
||||||
serve(
|
serve(
|
||||||
|
@ -541,6 +555,7 @@ mod tests {
|
||||||
handler.into_make_service(),
|
handler.into_make_service(),
|
||||||
);
|
);
|
||||||
serve(tcp_nodelay_listener().await, handler.into_make_service());
|
serve(tcp_nodelay_listener().await, handler.into_make_service());
|
||||||
|
#[cfg(unix)]
|
||||||
serve(UnixListener::bind("").unwrap(), handler.into_make_service());
|
serve(UnixListener::bind("").unwrap(), handler.into_make_service());
|
||||||
|
|
||||||
serve(
|
serve(
|
||||||
|
@ -551,6 +566,7 @@ mod tests {
|
||||||
tcp_nodelay_listener().await,
|
tcp_nodelay_listener().await,
|
||||||
handler.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
handler.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
||||||
);
|
);
|
||||||
|
#[cfg(unix)]
|
||||||
serve(
|
serve(
|
||||||
UnixListener::bind("").unwrap(),
|
UnixListener::bind("").unwrap(),
|
||||||
handler.into_make_service_with_connect_info::<UdsConnectInfo>(),
|
handler.into_make_service_with_connect_info::<UdsConnectInfo>(),
|
||||||
|
|
Loading…
Reference in a new issue