Skip to content

Commit

Permalink
update azure resource group regex to account for windows (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanpharvey authored Jun 27, 2024
1 parent 2d7534d commit 15aa48d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ddcommon/src/azure_app_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ impl AzureMetadata {
}

fn extract_resource_group(s: Option<String>) -> Option<String> {
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()))
})
}

Expand Down Expand Up @@ -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,
Expand All @@ -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(&[
Expand Down

0 comments on commit 15aa48d

Please sign in to comment.