diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-25 15:13:03 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-25 15:13:03 -0600 |
| commit | 0482895d6b34a3a3622979389ae62a40f3f64cf6 (patch) | |
| tree | 1f75e789c321163da65e6a8213d7eb3e7ea477cf /tests/common | |
| parent | ff81c53e472857e08eb1333f66f3d96487813732 (diff) | |
test: move builder functions to factory_bot module
Diffstat (limited to 'tests/common')
| -rw-r--r-- | tests/common/factory_bot.rs | 31 | ||||
| -rw-r--r-- | tests/common/mod.rs | 33 |
2 files changed, 31 insertions, 33 deletions
diff --git a/tests/common/factory_bot.rs b/tests/common/factory_bot.rs index 17c4c3d5..bd2cb163 100644 --- a/tests/common/factory_bot.rs +++ b/tests/common/factory_bot.rs @@ -1,6 +1,19 @@ 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; + +pub fn build<T: Default>() -> T { + return please::build(); +} + +pub fn build_with<T, F>(initializer: F) -> T +where + T: Default, + F: std::ops::FnOnce(&mut T), +{ + return please::build_with(initializer); +} pub fn create_request(f: impl std::ops::FnOnce(&mut HttpRequest)) -> CheckRequest { crate::common::build_with(|item: &mut CheckRequest| { @@ -11,3 +24,21 @@ pub fn create_request(f: impl std::ops::FnOnce(&mut HttpRequest)) -> CheckReques })); }) } + +pub fn create_test_request_with_headers( + headers: HashMap<String, String>, +) -> tonic::Request<CheckRequest> { + tonic::Request::new(create_request(|item: &mut HttpRequest| { + item.headers = headers; + })) +} + +pub fn create_headers_with_auth(auth_value: &str) -> HashMap<String, String> { + let mut headers = build::<HashMap<String, String>>(); + headers.insert(String::from("authorization"), auth_value.to_string()); + headers +} + +pub fn create_token() -> String { + return String::from("valid-token"); +} diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 9b089f16..4db87a2c 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,36 +1,3 @@ pub mod factory_bot; -use envoy_types::ext_authz::v3::pb::CheckRequest; -use envoy_types::pb::envoy::service::auth::v3::attribute_context::HttpRequest; use factory_bot::*; -use std::collections::HashMap; - -pub fn build<T: Default>() -> T { - return please::build(); -} - -pub fn build_with<T, F>(initializer: F) -> T -where - T: Default, - F: std::ops::FnOnce(&mut T), -{ - return please::build_with(initializer); -} - -pub fn create_test_request_with_headers( - headers: HashMap<String, String>, -) -> tonic::Request<CheckRequest> { - tonic::Request::new(create_request(|item: &mut HttpRequest| { - item.headers = headers; - })) -} - -pub fn create_headers_with_auth(auth_value: &str) -> HashMap<String, String> { - let mut headers = build::<HashMap<String, String>>(); - headers.insert(String::from("authorization"), auth_value.to_string()); - headers -} - -pub fn create_token() -> String { - return String::from("valid-token"); -} |
