From b7c3a1c50d616cf68155e76a9f143b98bc29fb35 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 20 Jun 2025 14:29:40 -0600 Subject: test: extract helper function to create a check request --- src/authorization/cedar_authorizer.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/authorization/cedar_authorizer.rs') diff --git a/src/authorization/cedar_authorizer.rs b/src/authorization/cedar_authorizer.rs index c1f5455d..49659d35 100644 --- a/src/authorization/cedar_authorizer.rs +++ b/src/authorization/cedar_authorizer.rs @@ -41,15 +41,15 @@ mod tests { use envoy_types::pb::envoy::service::auth::v3::{AttributeContext, attribute_context}; use std::collections::HashMap; - fn create_test_request_with_headers(headers: HashMap) -> CheckRequest { + fn create_request( + f: impl std::ops::FnOnce(&mut attribute_context::HttpRequest), + ) -> CheckRequest { please::build_with(|item: &mut CheckRequest| { item.attributes = Some(please::build_with(|item: &mut AttributeContext| { item.request = Some(please::build_with( |item: &mut attribute_context::Request| { item.http = Some(please::build_with( - |item: &mut attribute_context::HttpRequest| { - item.headers = headers; - }, + |item: &mut attribute_context::HttpRequest| f(item), )); }, )); @@ -57,6 +57,12 @@ mod tests { }) } + fn create_test_request_with_headers(headers: HashMap) -> CheckRequest { + return create_request(|item: &mut attribute_context::HttpRequest| { + item.headers = headers; + }); + } + #[test] fn test_cedar_authorizer_allows_valid_token() { let authorizer = CedarAuthorizer::new(); -- cgit v1.2.3