diff --git a/elfo-test/Cargo.toml b/elfo-test/Cargo.toml index b30a4641..a8e5d700 100644 --- a/elfo-test/Cargo.toml +++ b/elfo-test/Cargo.toml @@ -21,3 +21,4 @@ futures-intrusive = "0.5" futures = "0.3.12" tracing-subscriber = { version = "0.3", features = ["env-filter"] } once_cell = { version = "1.8.0" } +stability = "0.1.1" diff --git a/elfo-test/src/lib.rs b/elfo-test/src/lib.rs index 19d7cded..4370b79a 100644 --- a/elfo-test/src/lib.rs +++ b/elfo-test/src/lib.rs @@ -2,4 +2,7 @@ pub use proxy::{proxy, Proxy}; +#[cfg(feature = "unstable")] +pub use proxy::proxy_with_route; + mod proxy; diff --git a/elfo-test/src/proxy.rs b/elfo-test/src/proxy.rs index 594a433f..af1c42e9 100644 --- a/elfo-test/src/proxy.rs +++ b/elfo-test/src/proxy.rs @@ -224,7 +224,16 @@ fn testers(tx: shared::OneshotSender) -> Blueprint { }) } -pub async fn proxy(blueprint: Blueprint, config: impl for<'de> Deserializer<'de>) -> Proxy { +#[doc(hidden)] +#[stability::unstable] +pub async fn proxy_with_route( + blueprint: Blueprint, + route_filter: F, + config: impl for<'de> Deserializer<'de>, +) -> Proxy +where + F: Fn(&Envelope) -> bool + Send + Sync + 'static, +{ let _ = tracing_subscriber::fmt() .with_target(false) .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) @@ -244,7 +253,7 @@ pub async fn proxy(blueprint: Blueprint, config: impl for<'de> Deserializer<'de> let subject_addr = subject.addr(); testers.route_all_to(&subject); - subject.route_all_to(&testers); + subject.route_to(&testers, route_filter); // TODO: capture log messages. // TODO: capture metrics. @@ -271,6 +280,10 @@ pub async fn proxy(blueprint: Blueprint, config: impl for<'de> Deserializer<'de> } } +pub async fn proxy(blueprint: Blueprint, config: impl for<'de> Deserializer<'de>) -> Proxy { + proxy_with_route(blueprint, |_| true, config).await +} + #[cfg(test)] mod tests { use super::*;