summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-27 15:02:17 -0600
committermo khan <mo@mokhan.ca>2025-06-27 15:02:17 -0600
commit7bda8947c80fc507b722f321977522bd50377c17 (patch)
tree4d458daffbe08fc9ae80d55c0bdd0f004ba65ad2 /tests/support
parent22bd71354eafd9e7ef4d4579f9bf5e6181d44604 (diff)
test: move helpers to factory_bot module
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/factory_bot.rs17
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)
+}