Fixed an issue with array parameters is key-value pairs (#128) (#129)

* Fixed an issue with array parameters is key-value pairs (#128)

* Add hashtable property to xTestClassResource

* Add support for Hashtable property in DSC resource tests
This commit is contained in:
Raimund Andrée
2025-12-04 21:47:16 +01:00
committed by GitHub
parent c26e6b79d0
commit e32eb0fe51
4 changed files with 16 additions and 1 deletions
+1
View File
@@ -5,6 +5,7 @@
### Main changes
- Fixed Invoke-DscResource error when a class-based resource module path contains a space.
- Fixed an issue with array parameters is key-value pairs (#128).
[v2.0.7]: https://www.powershellgallery.com/packages/PSDesiredStateConfiguration/2.0.7
@@ -509,7 +509,7 @@ function ConvertTo-MOFInstance
$targetTypeName = $PropertyTypes[$p.Name].TypeConstraint
# see if the target type is an array
$asArray = $p.Name -eq 'DependsOn' -or $targetTypeName -match 'Array'
$asArray = $p.Name -eq 'DependsOn' -or $targetTypeName -match 'Array' -or ((-not [string]::IsNullOrEmpty($targetTypeName)) -and $targetTypeName.EndsWith('[]'))
# Convert the CIM typename to the appropriate .NET type to use
# to convert the input object into an appropriately encoded string
@@ -302,6 +302,8 @@ Describe "All types DSC resource tests" {
"uInt32ValueArray" {$dscResourcePropertyInfo.PropertyType | Should -Be '[UInt32[]]'}
"uInt64Value" {$dscResourcePropertyInfo.PropertyType | Should -Be '[UInt64]'}
"uInt64ValueArray" {$dscResourcePropertyInfo.PropertyType | Should -Be '[UInt64[]]'}
"HashTableValue" {$dscResourcePropertyInfo.PropertyType | Should -Be '[Hashtable]'}
}
}
}
@@ -350,6 +352,8 @@ Describe "All types DSC resource tests" {
$resource.uInt64Value.GetType().Name | Should -Be "UInt64"
$resource.uInt64ValueArray.GetType().Name | Should -Be "UInt64[]"
$resource.HashTableValue.GetType().Name | Should -Be "Hashtable"
# extra check for embedded objects
$resource.EmbClassObj.EmbClassStr1 | Should -Be "TestEmbObjValue"
$resource.EmbClassObjArray[0].EmbClassStr1 | Should -Be "TestEmbClassStr1Value"
@@ -400,6 +404,11 @@ configuration DSCAllTypesConfig
sInt32ValueArray = @(-2147483648)
uInt64ValueArray = @(18446744073709551615)
sInt64ValueArray = @(-9223372036854775808)
HashTableValue = @{
Key1 = 'Value1'
Key2 = 'Value2'
}
}
}
}
@@ -109,6 +109,9 @@ class xTestClassResource
[DscProperty()]
[Char[]] $char16ValueArray;
[DscProperty()]
[hashtable] $HashTableValue;
[void] Set()
{
@@ -257,6 +260,8 @@ class xTestClassResource
$this.Real32ValueArray = [single[]]::new(0)
$this.Real64ValueArray = [double[]]::new(0)
$this.HashTableValue = @{}
return $this
}
}