Skip to content

Commit 17331c9

Browse files
committed
Fix test results
1 parent 39ffc1c commit 17331c9

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

powershell-adapter/Tests/powershellgroup.config.tests.ps1

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Describe 'PowerShell adapter resource tests' {
275275
$out | Should -BeLike "*ERROR*Credential object 'Credential' requires both 'username' and 'password' properties*"
276276
}
277277

278-
It 'Config is able to return proper enum value' {
278+
It 'Config get is able to return proper enum value' {
279279
$yaml = @"
280280
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
281281
resources:
@@ -287,7 +287,28 @@ Describe 'PowerShell adapter resource tests' {
287287
"@
288288

289289
$out = dsc config get -i $yaml | ConvertFrom-Json
290+
Write-Verbose -Message ($out | ConvertTo-Json -Depth 10 | Out-String) -Verbose
290291
$LASTEXITCODE | Should -Be 0
291-
$out.results.result.actualState.result.Ensure | Should -Be 'Present'
292+
$out.results.result.actualState.Ensure | Should -Be 'Present'
293+
}
294+
295+
It 'Config export is able to return proper enum value' {
296+
$yaml = @"
297+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
298+
resources:
299+
- name: Working with class-based resources
300+
type: Microsoft.DSC/PowerShell
301+
properties:
302+
resources:
303+
- name: Class-resource Info
304+
type: TestClassResource/TestClassResource
305+
"@
306+
307+
$out = dsc config export -i $yaml | ConvertFrom-Json
308+
Write-Verbose -Message ($out | ConvertTo-Json -Depth 10 | Out-String) -Verbose
309+
$LASTEXITCODE | Should -Be 0
310+
$out.resources[0].properties.result.count | Should -Be 5
311+
$out.resources[0].properties.result[0].Name | Should -Be "Object1"
312+
$out.resources[0].properties.result[0].Prop1 | Should -Be "Property of object1"
292313
}
293314
}

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ function Invoke-DscOperation {
446446
$Result = @{}
447447
$raw_obj = $dscResourceInstance.Get()
448448
$ValidProperties | ForEach-Object {
449-
# if ($raw_obj.$_ -is [System.Enum]) {
450-
# $Result[$_] = $raw_obj.$_.ToString()
451-
# }
452-
# else {
453-
# $Result[$_] = $raw_obj.$_
454-
# }
455-
$Result[$_] = $raw_obj.$_
449+
if ($raw_obj.$_ -is [System.Enum]) {
450+
$Result[$_] = $raw_obj.$_.ToString()
451+
452+
}
453+
else
454+
{
455+
$Result[$_] = $raw_obj.$_
456+
}
456457
}
457-
$Result[$_] = $raw_obj.$_
458458
$addToActualState.properties = $Result
459459
}
460460
'Set' {
@@ -482,13 +482,15 @@ function Invoke-DscOperation {
482482
$raw_obj_array = $method.Invoke($null, $null)
483483
foreach ($raw_obj in $raw_obj_array) {
484484
$Result_obj = @{}
485-
$ValidProperties | ForEach-Object { if ($raw_obj.$_ -is [System.Enum]) {
486-
$Result[$_] = $raw_obj.$_.ToString()
485+
$ValidProperties | ForEach-Object {
486+
if ($raw_obj.$_ -is [System.Enum]) {
487+
$Result_obj[$_] = $raw_obj.$_.ToString()
487488
}
488-
else {
489-
$Result[$_] = $raw_obj.$_
490-
}
491-
}
489+
else
490+
{
491+
$Result_obj[$_] = $raw_obj.$_
492+
}
493+
}
492494
$resultArray += $Result_obj
493495
}
494496
$addToActualState = $resultArray

0 commit comments

Comments
 (0)