Skip to content

Commit 8a29cf9

Browse files
Copilotpsah434
andcommitted
Improve clarity of Find-OutputProperty function with better comments and parameter naming
Co-authored-by: psah434 <114955590+psah434@users.noreply.github.com>
1 parent dbbb846 commit 8a29cf9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arm-ttk/testcases/CreateUIDefinition/VMSizes-Must-Match-Template.test.ps1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $MainTemplateParameters
2222
#break
2323

2424
# Helper function to recursively search for a pattern in nested objects
25+
# Returns the top-level property name and the matching value when found
2526
function Find-OutputProperty {
2627
param(
2728
[Parameter(Mandatory=$true)]
@@ -31,22 +32,24 @@ function Find-OutputProperty {
3132
[string]$Pattern,
3233

3334
[Parameter(Mandatory=$false)]
34-
[string]$PropertyName = $null
35+
[string]$TopLevelPropertyName = $null
3536
)
3637

3738
foreach ($prop in $Object.psobject.properties) {
38-
$currentName = if ($PropertyName) { $PropertyName } else { $prop.Name }
39+
# Track the top-level property name for matching with template parameters
40+
# This is the property name we'll use to look up in MainTemplateParameters
41+
$topLevelName = if ($TopLevelPropertyName) { $TopLevelPropertyName } else { $prop.Name }
3942

4043
if ($prop.Value -is [string] -and $prop.Value -like $Pattern) {
41-
# Found a matching string value
44+
# Found a matching string value - return the top-level property name
4245
return [PSCustomObject]@{
43-
Name = $currentName
46+
Name = $topLevelName
4447
Value = $prop.Value
4548
}
4649
}
4750
elseif ($prop.Value -is [PSCustomObject] -or $prop.Value -is [System.Collections.Specialized.OrderedDictionary]) {
48-
# Recursively search nested objects
49-
$result = Find-OutputProperty -Object $prop.Value -Pattern $Pattern -PropertyName $currentName
51+
# Recursively search nested objects, preserving the top-level property name
52+
$result = Find-OutputProperty -Object $prop.Value -Pattern $Pattern -TopLevelPropertyName $topLevelName
5053
if ($result) {
5154
return $result
5255
}

0 commit comments

Comments
 (0)