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 committed Jul 1, 2024
1 parent 2212644 commit 3f819b8
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 @@ -103,11 +103,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 @@ -426,7 +426,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 @@ -443,6 +443,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 3f819b8

Please sign in to comment.