From 0482895d6b34a3a3622979389ae62a40f3f64cf6 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 25 Jun 2025 15:13:03 -0600 Subject: test: move builder functions to factory_bot module --- tests/common/factory_bot.rs | 31 +++++++++++++++++++++++++++++++ tests/common/mod.rs | 33 --------------------------------- 2 files changed, 31 insertions(+), 33 deletions(-) (limited to 'tests/common') 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 { + return please::build(); +} + +pub fn build_with(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, +) -> tonic::Request { + tonic::Request::new(create_request(|item: &mut HttpRequest| { + item.headers = headers; + })) +} + +pub fn create_headers_with_auth(auth_value: &str) -> HashMap { + let mut headers = build::>(); + 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 { - return please::build(); -} - -pub fn build_with(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, -) -> tonic::Request { - tonic::Request::new(create_request(|item: &mut HttpRequest| { - item.headers = headers; - })) -} - -pub fn create_headers_with_auth(auth_value: &str) -> HashMap { - let mut headers = build::>(); - headers.insert(String::from("authorization"), auth_value.to_string()); - headers -} - -pub fn create_token() -> String { - return String::from("valid-token"); -} -- cgit v1.2.3