From bc1df596ba334f8e036bd71fa9fbfadaf0c99125 Mon Sep 17 00:00:00 2001 From: Duncan Harvey Date: Tue, 25 Jun 2024 14:35:34 -0400 Subject: [PATCH] update azure resource group regex to account for windows --- ddcommon/src/azure_app_services.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/ddcommon/src/azure_app_services.rs b/ddcommon/src/azure_app_services.rs index 18dca04ea..13d0a4596 100644 --- a/ddcommon/src/azure_app_services.rs +++ b/ddcommon/src/azure_app_services.rs @@ -95,11 +95,11 @@ impl AzureMetadata { } fn extract_resource_group(s: Option) -> Option { - let re: Regex = Regex::new(r"(.+)\+(.+)-(.+)-(.+)").unwrap(); + let re: Regex = Regex::new(r".+\+(.+)-.+webspace(-Linux)?").unwrap(); s.as_ref().and_then(|text| { re.captures(text) - .and_then(|caps| caps.get(2).map(|m| m.as_str().to_string())) + .and_then(|caps| caps.get(1).map(|m| m.as_str().to_string())) }) } @@ -399,7 +399,7 @@ mod tests { } #[test] - fn test_extract_resource_group_pattern_match() { + fn test_extract_resource_group_pattern_match_linux() { let mocked_env = MockEnv::new(&[ ( WEBSITE_ONWER_NAME, @@ -416,6 +416,24 @@ mod tests { assert_eq!(metadata.get_resource_group(), expected_resource_group); } + #[test] + fn test_extract_resource_group_pattern_match_windows() { + let mocked_env = MockEnv::new(&[ + ( + WEBSITE_ONWER_NAME, + "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace", + ), + ("FUNCTIONS_WORKER_RUNTIME", "node"), + ("FUNCTIONS_EXTENSION_VERSION", "~4"), + ]); + + let metadata = AzureMetadata::new_function(mocked_env).unwrap(); + + let expected_resource_group = "test-rg"; + + assert_eq!(metadata.get_resource_group(), expected_resource_group); + } + #[test] fn test_extract_resource_group_no_pattern_match() { let mocked_env = MockEnv::new(&[