summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-25 15:08:55 -0600
committermo khan <mo@mokhan.ca>2025-06-25 15:08:55 -0600
commitff81c53e472857e08eb1333f66f3d96487813732 (patch)
tree13ee8e8d477f6c186ce7dc2d735e683a0f9f35d9
parent25412b5ad670d5b8809d399aae4ab63bd5e1de40 (diff)
test: extract factory_bot module
-rw-r--r--tests/authorization/cedar_authorizer_test.rs1
-rw-r--r--tests/authorization/check_service_test.rs2
-rw-r--r--tests/common/factories.rs0
-rw-r--r--tests/common/factory_bot.rs13
-rw-r--r--tests/common/mod.rs16
5 files changed, 18 insertions, 14 deletions
diff --git a/tests/authorization/cedar_authorizer_test.rs b/tests/authorization/cedar_authorizer_test.rs
index 1012d917..c74a2042 100644
--- a/tests/authorization/cedar_authorizer_test.rs
+++ b/tests/authorization/cedar_authorizer_test.rs
@@ -1,5 +1,6 @@
#[cfg(test)]
mod tests {
+ use crate::common::factory_bot::create_request;
use crate::common::*;
use authzd::Authorizer;
use authzd::CedarAuthorizer;
diff --git a/tests/authorization/check_service_test.rs b/tests/authorization/check_service_test.rs
index 23655ffb..dadb6d1a 100644
--- a/tests/authorization/check_service_test.rs
+++ b/tests/authorization/check_service_test.rs
@@ -1,7 +1,7 @@
#[cfg(test)]
mod tests {
- use crate::common::create_request;
use crate::common::create_token;
+ use crate::common::factory_bot::create_request;
use authzd::CedarAuthorizer;
use authzd::CheckService;
use envoy_types::ext_authz::v3::pb::Authorization;
diff --git a/tests/common/factories.rs b/tests/common/factories.rs
deleted file mode 100644
index e69de29b..00000000
--- a/tests/common/factories.rs
+++ /dev/null
diff --git a/tests/common/factory_bot.rs b/tests/common/factory_bot.rs
new file mode 100644
index 00000000..17c4c3d5
--- /dev/null
+++ b/tests/common/factory_bot.rs
@@ -0,0 +1,13 @@
+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};
+
+pub fn create_request(f: impl std::ops::FnOnce(&mut HttpRequest)) -> CheckRequest {
+ crate::common::build_with(|item: &mut CheckRequest| {
+ item.attributes = Some(please::build_with(|item: &mut AttributeContext| {
+ item.request = Some(please::build_with(|item: &mut Request| {
+ item.http = Some(please::build_with(|item: &mut HttpRequest| f(item)));
+ }));
+ }));
+ })
+}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index aab3a412..9b089f16 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,8 +1,8 @@
-mod factories;
+pub mod factory_bot;
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 envoy_types::pb::envoy::service::auth::v3::attribute_context::HttpRequest;
+use factory_bot::*;
use std::collections::HashMap;
pub fn build<T: Default>() -> T {
@@ -17,16 +17,6 @@ where
return please::build_with(initializer);
}
-pub fn create_request(f: impl std::ops::FnOnce(&mut HttpRequest)) -> CheckRequest {
- build_with(|item: &mut CheckRequest| {
- item.attributes = Some(please::build_with(|item: &mut AttributeContext| {
- item.request = Some(please::build_with(|item: &mut Request| {
- item.http = Some(please::build_with(|item: &mut HttpRequest| f(item)));
- }));
- }));
- })
-}
-
pub fn create_test_request_with_headers(
headers: HashMap<String, String>,
) -> tonic::Request<CheckRequest> {