Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serverless Mini Agent] Update Azure Resource Group Regex to Account for Windows #504

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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