diff options
Diffstat (limited to 'tests/support')
| -rw-r--r-- | tests/support/factory_bot.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/support/factory_bot.rs b/tests/support/factory_bot.rs index c64b53a2..15c6f1f3 100644 --- a/tests/support/factory_bot.rs +++ b/tests/support/factory_bot.rs @@ -2,6 +2,8 @@ use envoy_types::ext_authz::v3::pb::CheckRequest; use envoy_types::pb::envoy::service::auth::v3::AttributeContext; use envoy_types::pb::envoy::service::auth::v3::attribute_context::{HttpRequest, Request}; use std::collections::HashMap; +use std::net::SocketAddr; +use tonic::transport::Channel; #[allow(dead_code)] pub fn build<T: Default>() -> T { @@ -39,3 +41,18 @@ pub fn build_cedar_authorizer() -> authzd::CedarAuthorizer { let path = realpath.as_path(); authzd::CedarAuthorizer::new_from(path) } + +pub async fn build_channel(addr: SocketAddr) -> Channel { + Channel::from_shared(format!("http://{}", addr)) + .expect("Failed to create channel") + .connect() + .await + .expect("Failed to connect to server") +} + +pub async fn build_rpc_client<T, F>(addr: SocketAddr, f: F) -> T +where + F: FnOnce(Channel) -> T, +{ + f(build_channel(addr).await) +} |
