summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-06-25 15:29:33 -0600
committermo khan <mo@mokhan.ca>2025-06-25 15:29:33 -0600
commit13205895041cc545a41be9552fe28d5dc1c7318a (patch)
tree05a780c93a4a404c162a00c2f6f101f546bb6419
parent0482895d6b34a3a3622979389ae62a40f3f64cf6 (diff)
test: extract a build_headers function
-rw-r--r--tests/common/factory_bot.rs15
-rw-r--r--tests/integration_tests.rs9
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: Default>() -> T {
return please::build();
}
@@ -33,10 +34,18 @@ pub fn create_test_request_with_headers(
}))
}
+pub fn build_headers(headers: Vec<(String, String)>) -> HashMap<String, String> {
+ return build_with(|item: &mut HashMap<String, String>| {
+ for (key, value) in headers {
+ item.insert(key, value);
+ }
+ });
+}
+
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
+ return build_with(|item: &mut HashMap<String, String>| {
+ 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());