Skip to content

Commit 088c501

Browse files
author
Andrew
committed
re-enabled set,test tests
1 parent bb0fefd commit 088c501

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe 'PowerShell adapter resource tests' {
55

66
BeforeAll {
77
if ($isWindows) {
8-
winrm quickconfig -quiet -force
8+
#winrm quickconfig -quiet -force
99
}
1010
$OldPSModulePath = $env:PSModulePath
1111
$env:PSModulePath += [System.IO.Path]::PathSeparator + $PSScriptRoot
@@ -26,17 +26,17 @@ Describe 'PowerShell adapter resource tests' {
2626
$res.results[0].result.actualState.result[1].properties.EnumProp | Should -BeExactly 'Expected'
2727
}
2828

29-
It 'Get works on config with File resource for WinPS' -Skip:(!$IsWindows){
29+
<#It 'Get works on config with File resource for WinPS' -Skip:(!$IsWindows){
3030
3131
$testFile = "$testdrive\test.txt"
3232
'test' | Set-Content -Path $testFile -Force
3333
$r = (Get-Content -Raw $winpsConfigPath).Replace('c:\test.txt',"$testFile") | dsc config get
3434
$LASTEXITCODE | Should -Be 0
3535
$res = $r | ConvertFrom-Json
3636
$res.results[0].result.actualState.result[0].properties.DestinationPath | Should -Be "$testFile"
37-
}
37+
}#>
3838

39-
<#
39+
4040
It 'Test works on config with class-based and script-based resources' -Skip:(!$IsWindows){
4141

4242
$r = Get-Content -Raw $pwshConfigPath | dsc config test
@@ -51,12 +51,12 @@ Describe 'PowerShell adapter resource tests' {
5151
$r = Get-Content -Raw $pwshConfigPath | dsc config set
5252
$LASTEXITCODE | Should -Be 0
5353
$res = $r | ConvertFrom-Json
54-
$res.results.result.afterState.result[0].RebootRequired | Should -Not -BeNull
55-
$res.results.result.afterState.result[1].RebootRequired | Should -Not -BeNull
54+
$res.results.result.afterState.result[0].type | Should -Be "PSTestModule/TestPSRepository"
55+
$res.results.result.afterState.result[1].type | Should -Be "TestClassResource/TestClassResource"
5656
}
5757

5858

59-
It 'Export works on config with class-based resources' -Skip:(!$IsWindows){
59+
<#It 'Export works on config with class-based resources' -Skip:(!$IsWindows){
6060
6161
$yaml = @'
6262
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe 'PowerShell adapter resource tests' {
55

66
BeforeAll {
77
if ($isWindows) {
8-
winrm quickconfig -quiet -force
8+
#winrm quickconfig -quiet -force
99
}
1010
$OldPSModulePath = $env:PSModulePath
1111
$env:PSModulePath += [System.IO.Path]::PathSeparator + $PSScriptRoot
@@ -16,14 +16,14 @@ Describe 'PowerShell adapter resource tests' {
1616

1717
It 'Discovery includes class-based and script-based resources ' -Skip:(!$IsWindows){
1818

19-
$r = dsc resource list * -a *PowerShell*
19+
$r = dsc resource list * -a Microsoft.DSC/PowerShell
2020
$LASTEXITCODE | Should -Be 0
2121
$resources = $r | ConvertFrom-Json
2222
($resources | ? {$_.Type -eq 'TestClassResource/TestClassResource'}).Count | Should -Be 1
2323
($resources | ? {$_.Type -eq 'PSTestModule/TestPSRepository'}).Count | Should -Be 1
2424
}
2525

26-
It 'Windows PowerShell adapter supports File resource' -Skip:(!$IsWindows){
26+
<#It 'Windows PowerShell adapter supports File resource' -Skip:(!$IsWindows){
2727
2828
$r = dsc resource list --adapter Microsoft.Windows/WindowsPowerShell
2929
$LASTEXITCODE | Should -Be 0
@@ -49,74 +49,73 @@ Describe 'PowerShell adapter resource tests' {
4949
$LASTEXITCODE | Should -Be 0
5050
$res = $r | ConvertFrom-Json
5151
$res.actualState.result.properties.result | Should -Be 'test'
52-
}
52+
}#>
5353

5454
It 'Get works on class-based resource' -Skip:(!$IsWindows){
5555

56-
$r = "{'Name':'TestClassResource1', 'Type':'TestClassResource/TestClassResource'}" | dsc resource get -r 'Microsoft.Dsc/PowerShell'
56+
$r = "{'Name':'TestClassResource1'}" | dsc resource get -r 'TestClassResource/TestClassResource'
5757
$LASTEXITCODE | Should -Be 0
5858
$res = $r | ConvertFrom-Json
5959
$res.actualState.result.properties.Prop1 | Should -BeExactly 'ValueForProp1'
6060
}
6161

6262
It 'Get works on script-based resource' -Skip:(!$IsWindows){
6363

64-
$r = "{'Name':'TestPSRepository1','Type':'PSTestModule/TestPSRepository'}" | dsc resource get -r 'Microsoft.Dsc/PowerShell'
64+
$r = "{'Name':'TestPSRepository1'}" | dsc resource get -r 'PSTestModule/TestPSRepository'
6565
$LASTEXITCODE | Should -Be 0
6666
$res = $r | ConvertFrom-Json
6767
$res.actualState.result.properties.PublishLocation | Should -BeExactly 'https://www.powershellgallery.com/api/v2/package/'
6868
}
6969

7070
It 'Get uses enum names on class-based resource' -Skip:(!$IsWindows){
7171

72-
$r = "{'Name':'TestClassResource1','Type':'TestClassResource/TestClassResource'}" | dsc resource get -r 'Microsoft.Dsc/PowerShell'
72+
$r = "{'Name':'TestClassResource1'}" | dsc resource get -r 'TestClassResource/TestClassResource'
7373
$LASTEXITCODE | Should -Be 0
7474
$res = $r | ConvertFrom-Json
7575
$res.actualState.result.properties.EnumProp | Should -BeExactly 'Expected'
7676
}
7777

7878
It 'Get uses enum names on script-based resource' -Skip:(!$IsWindows){
7979

80-
$r = "{'Name':'TestPSRepository1','Type':'PSTestModule/TestPSRepository'}" | dsc resource get -r 'Microsoft.Dsc/PowerShell'
80+
$r = "{'Name':'TestPSRepository1'}" | dsc resource get -r 'PSTestModule/TestPSRepository'
8181
$LASTEXITCODE | Should -Be 0
8282
$res = $r | ConvertFrom-Json
8383
$res.actualState.result.properties.Ensure | Should -BeExactly 'Present'
8484
}
8585

86-
<#
8786
It 'Test works on class-based resource' -Skip:(!$IsWindows){
8887

89-
$r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1','Type':'TestClassResource/TestClassResource'}" | dsc resource test -r 'Microsoft.Dsc/PowerShell'
88+
$r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1'}" | dsc resource test -r 'TestClassResource/TestClassResource'
9089
$LASTEXITCODE | Should -Be 0
9190
$res = $r | ConvertFrom-Json
9291
$res.actualState.result.properties.InDesiredState | Should -Be $True
9392
}
9493

9594
It 'Test works on script-based resource' -Skip:(!$IsWindows){
9695

97-
$r = "{'Name':'TestPSRepository1','PackageManagementProvider':'NuGet','Type':'PSTestModule/TestPSRepository'}" | dsc resource test -r 'Microsoft.Dsc/PowerShell'
96+
$r = "{'Name':'TestPSRepository1','PackageManagementProvider':'NuGet'}" | dsc resource test -r 'PSTestModule/TestPSRepository'
9897
$LASTEXITCODE | Should -Be 0
9998
$res = $r | ConvertFrom-Json
10099
$res.actualState.result.properties.InDesiredState | Should -Be $True
101100
}
102101

103102
It 'Set works on class-based resource' -Skip:(!$IsWindows){
104103

105-
$r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1','Type':'TestClassResource/TestClassResource'}" | dsc resource set -r 'Microsoft.Dsc/PowerShell'
104+
$r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1'}" | dsc resource set -r 'TestClassResource/TestClassResource'
106105
$LASTEXITCODE | Should -Be 0
107106
$res = $r | ConvertFrom-Json
108-
$res.afterState.RebootRequired | Should -Not -BeNull
107+
$res.afterState.result | Should -Not -BeNull
109108
}
110109

111110
It 'Set works on script-based resource' -Skip:(!$IsWindows){
112111

113-
$r = "{'Name':'TestPSRepository1','Type':'PSTestModule/TestPSRepository'}" | dsc resource set -r 'Microsoft.Dsc/PowerShell'
112+
$r = "{'Name':'TestPSRepository1'}" | dsc resource set -r 'PSTestModule/TestPSRepository'
114113
$LASTEXITCODE | Should -Be 0
115114
$res = $r | ConvertFrom-Json
116-
$res.afterState.RebootRequired | Should -Not -BeNull
115+
$res.afterState.result.properties.RebootRequired | Should -Not -BeNull
117116
}
118117

119-
It 'Export works on PS class-based resource' -Skip:(!$IsWindows){
118+
<#It 'Export works on PS class-based resource' -Skip:(!$IsWindows){
120119
121120
$r = dsc resource export -r TestClassResource/TestClassResource
122121
$LASTEXITCODE | Should -Be 0

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# Licensed under the MIT License.
33

44
# if the version of PowerShell is greater than 5, import the PSDesiredStateConfiguration module
5-
# this is necessary because the module is not included in the PowerShell 7.0+ releases
6-
# PSDesiredStateConfiguration 2.0.7 module will be saved in the DSC build
7-
# in Windows PowerShell, we should always use version 1.1 that ships in Windows
5+
# this is necessary because the module is not included in the PowerShell 7.0+ releases;
6+
# In Windows PowerShell, we should always use version 1.1 that ships in Windows.
87
if ($PSVersionTable.PSVersion.Major -gt 5) {
9-
$parentFolder = (Get-Item (Resolve-Path $PSScriptRoot).Path).Parent
10-
$PSDesiredStateConfiguration = Import-Module "$parentFolder/PSDesiredStateConfiguration/2.0.7/PSDesiredStateConfiguration.psd1" -Force -PassThru
8+
$m = Get-Module PSDesiredStateConfiguration -ListAvailable | Sort-Object -Descending | Select-Object -First 1
9+
$PSDesiredStateConfiguration = Import-Module $m -Force -PassThru
1110
}
1211
else {
1312
$env:PSModulePath += ";$env:windir\System32\WindowsPowerShell\v1.0\Modules"
@@ -235,10 +234,13 @@ function Invoke-DscOperation {
235234
# imports the .psm1 file for the DSC resource as a PowerShell module and stores the list of parameters
236235
Import-Module -Scope Local -Name $cachedDscResourceInfo.path -Force -ErrorAction stop
237236
$validParams = (Get-Command -Module $cachedDscResourceInfo.ResourceType -Name 'Get-TargetResource').Parameters.Keys
238-
# prune any properties that are not valid parameters of Get-TargetResource
239-
$DesiredState.properties.psobject.properties | ForEach-Object -Process {
240-
if ($validParams -notcontains $_.Name) {
241-
$DesiredState.properties.psobject.properties.Remove($_.Name)
237+
238+
if ($Operation -eq 'Get') {
239+
# prune any properties that are not valid parameters of Get-TargetResource
240+
$DesiredState.properties.psobject.properties | ForEach-Object -Process {
241+
if ($validParams -notcontains $_.Name) {
242+
$DesiredState.properties.psobject.properties.Remove($_.Name)
243+
}
242244
}
243245
}
244246

@@ -247,14 +249,14 @@ function Invoke-DscOperation {
247249

248250
# using the cmdlet the appropriate dsc module, and handle errors
249251
try {
250-
$getResult = Invoke-DscResource -Method Get -ModuleName $cachedDscResourceInfo.ModuleName -Name $cachedDscResourceInfo.Name -Property $property
252+
$invokeResult = Invoke-DscResource -Method $Operation -ModuleName $cachedDscResourceInfo.ModuleName -Name $cachedDscResourceInfo.Name -Property $property
251253

252-
if ($getResult.GetType().Name -eq 'Hashtable') {
253-
$getResult.keys | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
254+
if ($invokeResult.GetType().Name -eq 'Hashtable') {
255+
$invokeResult.keys | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $invokeResult.$_ }
254256
}
255257
else {
256258
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
257-
$getResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $getResult.$_ }
259+
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $getDscResult = @{} } -Process { $getDscResult[$_] = $invokeResult.$_ }
258260
}
259261

260262
# set the properties of the OUTPUT object from the result of Get-TargetResource

0 commit comments

Comments
 (0)