From 13205895041cc545a41be9552fe28d5dc1c7318a Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 25 Jun 2025 15:29:33 -0600 Subject: test: extract a build_headers function --- tests/common/factory_bot.rs | 15 ++++++++++++--- tests/integration_tests.rs | 9 ++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/common/factory_bot.rs b/tests/common/factory_bot.rs index bd2cb163..a16a1213 100644 --- a/tests/common/factory_bot.rs +++ b/tests/common/factory_bot.rs @@ -3,6 +3,7 @@ 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; +#[allow(dead_code)] pub fn build() -> T { return please::build(); } @@ -33,10 +34,18 @@ pub fn create_test_request_with_headers( })) } +pub fn build_headers(headers: Vec<(String, String)>) -> HashMap { + return build_with(|item: &mut HashMap| { + for (key, value) in headers { + item.insert(key, value); + } + }); +} + pub fn create_headers_with_auth(auth_value: &str) -> HashMap { - let mut headers = build::>(); - headers.insert(String::from("authorization"), auth_value.to_string()); - headers + return build_with(|item: &mut HashMap| { + item.insert(String::from("authorization"), String::from(auth_value)); + }); } pub fn create_token() -> String { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index fc31a037..41c3bf29 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -9,9 +9,12 @@ mod common; async fn test_success_response() { let authorizer = Arc::new(CedarAuthorizer::new()); let server = CheckService::new(authorizer); - - let headers = common::factory_bot::create_headers_with_auth("Bearer valid-token"); - let request = common::factory_bot::create_test_request_with_headers(headers); + let request = common::factory_bot::create_test_request_with_headers( + common::factory_bot::build_headers(vec![( + "authorization".to_string(), + "Bearer valid-token".to_string(), + )]), + ); let response = server.check(request).await; assert!(response.is_ok()); -- cgit v1.2.3