Skip to content

Commit d8a12d3

Browse files
authored
Merge pull request #411 from anmenaga/psadapter_updates1
Set/Test/Export and other updates for PSAdapter
2 parents 0a934c5 + 8b75f29 commit d8a12d3

13 files changed

+107
-655
lines changed

build.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ $skip_test_projects_on_windows = @("tree-sitter-dscexpression")
210210
}
211211
}
212212

213-
Save-PSResource -Path $target -Name 'PSDesiredStateConfiguration' -Version '2.0.7' -Repository PSGallery -TrustRepository
214-
215213
if ($failed) {
216214
Write-Host -ForegroundColor Red "Build failed"
217215
exit 1

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ Describe 'PowerShell adapter resource tests' {
3434
$LASTEXITCODE | Should -Be 0
3535
$res = $r | ConvertFrom-Json
3636
$res.results[0].result.actualState.result[0].properties.DestinationPath | Should -Be "$testFile"
37-
}
38-
39-
<#
37+
}
38+
4039
It 'Test works on config with class-based and script-based resources' -Skip:(!$IsWindows){
4140

4241
$r = Get-Content -Raw $pwshConfigPath | dsc config test
@@ -51,8 +50,8 @@ Describe 'PowerShell adapter resource tests' {
5150
$r = Get-Content -Raw $pwshConfigPath | dsc config set
5251
$LASTEXITCODE | Should -Be 0
5352
$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
53+
$res.results.result.afterState.result[0].type | Should -Be "PSTestModule/TestPSRepository"
54+
$res.results.result.afterState.result[1].type | Should -Be "TestClassResource/TestClassResource"
5655
}
5756

5857

@@ -66,51 +65,47 @@ Describe 'PowerShell adapter resource tests' {
6665
properties:
6766
resources:
6867
- name: Class-resource Info
69-
type: PSTestModule/TestClassResource
68+
type: TestClassResource/TestClassResource
7069
'@
7170
$out = $yaml | dsc config export
7271
$LASTEXITCODE | Should -Be 0
7372
$res = $out | ConvertFrom-Json
7473
$res.'$schema' | Should -BeExactly 'https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json'
7574
$res.'resources' | Should -Not -BeNullOrEmpty
76-
$res.resources.count | Should -Be 5
77-
$res.resources[0].properties.Name | Should -Be "Object1"
78-
$res.resources[0].properties.Prop1 | Should -Be "Property of object1"
75+
$res.resources[0].properties.result.count | Should -Be 5
76+
$res.resources[0].properties.result[0].Name | Should -Be "Object1"
77+
$res.resources[0].properties.result[0].Prop1 | Should -Be "Property of object1"
7978
}
8079

81-
#>
82-
8380
It 'Custom psmodulepath in config works' -Skip:(!$IsWindows){
8481

8582
$OldPSModulePath = $env:PSModulePath
86-
Copy-Item -Recurse -Force -Path "$PSScriptRoot/PSTestModule" -Destination $TestDrive
87-
Rename-Item -Path "$PSScriptRoot/PSTestModule" -NewName "_PSTestModule"
83+
Copy-Item -Recurse -Force -Path "$PSScriptRoot/TestClassResource" -Destination $TestDrive
84+
Rename-Item -Path "$PSScriptRoot/TestClassResource" -NewName "_TestClassResource"
8885

8986
try {
9087
$yaml = @"
91-
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
88+
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
89+
resources:
90+
- name: Working with class-based resources
91+
type: Microsoft.DSC/PowerShell
92+
properties:
93+
psmodulepath: `$env:PSModulePath;$TestDrive
9294
resources:
93-
- name: Working with class-based resources
94-
type: Microsoft.DSC/PowerShell
95-
properties:
96-
psmodulepath: `$env:PSModulePath;$TestDrive
97-
resources:
98-
- name: Class-resource Info
99-
type: PSTestModule/TestClassResource
95+
- name: Class-resource Info
96+
type: TestClassResource/TestClassResource
10097
"@
101-
<#
10298
$out = $yaml | dsc config export
10399
$LASTEXITCODE | Should -Be 0
104100
$res = $out | ConvertFrom-Json
105101
$res.'$schema' | Should -BeExactly 'https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json'
106102
$res.'resources' | Should -Not -BeNullOrEmpty
107-
$res.resources.count | Should -Be 5
108-
$res.resources[0].properties.Name | Should -Be "Object1"
109-
$res.resources[0].properties.Prop1 | Should -Be "Property of object1"
110-
#>
103+
$res.resources[0].properties.result.count | Should -Be 5
104+
$res.resources[0].properties.result[0].Name | Should -Be "Object1"
105+
$res.resources[0].properties.result[0].Prop1 | Should -Be "Property of object1"
111106
}
112107
finally {
113-
Rename-Item -Path "$PSScriptRoot/_PSTestModule" -NewName "PSTestModule"
108+
Rename-Item -Path "$PSScriptRoot/_TestClassResource" -NewName "TestClassResource"
114109
$env:PSModulePath = $OldPSModulePath
115110
}
116111
}

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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
@@ -53,87 +53,84 @@ Describe 'PowerShell adapter resource tests' {
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

119118
It 'Export works on PS class-based resource' -Skip:(!$IsWindows){
120119

121120
$r = dsc resource export -r TestClassResource/TestClassResource
122121
$LASTEXITCODE | Should -Be 0
123122
$res = $r | ConvertFrom-Json
124-
$res.resources.count | Should -Be 5
125-
$res.resources[0].type | Should -Be "TestClassResource/TestClassResource"
126-
$res.resources[0].properties.Name | Should -Be "Object1"
127-
$res.resources[0].properties.Prop1 | Should -Be "Property of object1"
123+
$res.resources[0].properties.result.count | Should -Be 5
124+
$res.resources[0].properties.result[0].Name | Should -Be "Object1"
125+
$res.resources[0].properties.result[0].Prop1 | Should -Be "Property of object1"
128126
}
129127

130128
It 'Get --all works on PS class-based resource' -Skip:(!$IsWindows){
131129

132130
$r = dsc resource get --all -r TestClassResource/TestClassResource
133131
$LASTEXITCODE | Should -Be 0
134132
$res = $r | ConvertFrom-Json
135-
$res.count | Should -Be 5
136-
$res | % {$_.actualState | Should -Not -BeNullOrEmpty}
133+
$res.actualState.result.count | Should -Be 5
134+
$res.actualState.result| % {$_.Name | Should -Not -BeNullOrEmpty}
137135
}
138-
#>
139136
}

powershell-adapter/copy_files.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
powershell.resource.ps1
1+
./psDscAdapter/powershell.resource.ps1
22
./psDscAdapter/psDscAdapter.psd1
3-
./psDscAdapter/psDscAdapter.psm1
4-
./psDscAdapter/Configuration/BaseRegistration/BaseResource.Schema.mof
5-
./psDscAdapter/Configuration/BaseRegistration/MSFT_MetaConfigurationExtensionClasses.Schema.mof
6-
./psDscAdapter/Configuration/BaseRegistration/en-us/BaseResource.Schema.mfl
7-
./psDscAdapter/Configuration/BaseRegistration/en-us/MSFT_MetaConfigurationExtensionClasses.Schema.mfl
8-
./psDscAdapter/helpers/DscResourceInfo.psm1
3+
./psDscAdapter/psDscAdapter.psm1

powershell-adapter/powershell.dsc.resource.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"-NonInteractive",
1616
"-NoProfile",
1717
"-Command",
18-
"./powershell.resource.ps1 List"
18+
"./psDscAdapter/powershell.resource.ps1 List"
1919
]
2020
},
2121
"config": "full"
@@ -27,7 +27,7 @@
2727
"-NonInteractive",
2828
"-NoProfile",
2929
"-Command",
30-
"$Input | ./powershell.resource.ps1 Get"
30+
"$Input | ./psDscAdapter/powershell.resource.ps1 Get"
3131
],
3232
"input": "stdin"
3333
},
@@ -38,7 +38,7 @@
3838
"-NonInteractive",
3939
"-NoProfile",
4040
"-Command",
41-
"$Input | ./powershell.resource.ps1 Set"
41+
"$Input | ./psDscAdapter/powershell.resource.ps1 Set"
4242
],
4343
"input": "stdin",
4444
"implementsPretest": true,
@@ -51,7 +51,7 @@
5151
"-NonInteractive",
5252
"-NoProfile",
5353
"-Command",
54-
"$Input | ./powershell.resource.ps1 Test"
54+
"$Input | ./psDscAdapter/powershell.resource.ps1 Test"
5555
],
5656
"input": "stdin",
5757
"return": "state"
@@ -63,7 +63,7 @@
6363
"-NonInteractive",
6464
"-NoProfile",
6565
"-Command",
66-
"$Input | ./powershell.resource.ps1 Export"
66+
"$Input | ./psDscAdapter/powershell.resource.ps1 Export"
6767
],
6868
"input": "stdin",
6969
"return": "state"
@@ -75,7 +75,7 @@
7575
"-NonInteractive",
7676
"-NoProfile",
7777
"-Command",
78-
"$Input | ./powershell.resource.ps1 Validate"
78+
"$Input | ./psDscAdapter/powershell.resource.ps1 Validate"
7979
],
8080
"input": "stdin"
8181
},

powershell-adapter/psDscAdapter/Configuration/BaseRegistration/BaseResource.schema.mof

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)