Skip to content

Commit e07e5bd

Browse files
author
Andrew
committed
Stage 3
1 parent d557c6d commit e07e5bd

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Describe 'PowerShell adapter resource tests' {
2424
Remove-Item -Force -ea SilentlyContinue -Path $cacheFilePath
2525
}
2626

27-
It 'Get works on config with class-based resources' -Skip:(!$IsWindows){
27+
It 'Get works on config with class-based resources' {
2828

2929
$r = Get-Content -Raw $pwshConfigPath | dsc config get
3030
$LASTEXITCODE | Should -Be 0
@@ -33,23 +33,23 @@ Describe 'PowerShell adapter resource tests' {
3333
$res.results[0].result.actualState.result[0].properties.EnumProp | Should -BeExactly 'Expected'
3434
}
3535

36-
It 'Test works on config with class-based resources' -Skip:(!$IsWindows){
36+
It 'Test works on config with class-based resources' {
3737

3838
$r = Get-Content -Raw $pwshConfigPath | dsc config test
3939
$LASTEXITCODE | Should -Be 0
4040
$res = $r | ConvertFrom-Json
4141
$res.results[0].result.actualState.result[0] | Should -Not -BeNull
4242
}
4343

44-
It 'Set works on config with class-based resources' -Skip:(!$IsWindows){
44+
It 'Set works on config with class-based resources' {
4545

4646
$r = Get-Content -Raw $pwshConfigPath | dsc config set
4747
$LASTEXITCODE | Should -Be 0
4848
$res = $r | ConvertFrom-Json
4949
$res.results.result.afterState.result[0].type | Should -Be "TestClassResource/TestClassResource"
5050
}
5151

52-
It 'Export works on config with class-based resources' -Skip:(!$IsWindows){
52+
It 'Export works on config with class-based resources' {
5353

5454
$yaml = @'
5555
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
@@ -71,7 +71,7 @@ Describe 'PowerShell adapter resource tests' {
7171
$res.resources[0].properties.result[0].Prop1 | Should -Be "Property of object1"
7272
}
7373

74-
It 'Custom psmodulepath in config works' -Skip:(!$IsWindows){
74+
It 'Custom psmodulepath in config works' {
7575

7676
$OldPSModulePath = $env:PSModulePath
7777
Copy-Item -Recurse -Force -Path "$PSScriptRoot/TestClassResource" -Destination $TestDrive
@@ -104,7 +104,7 @@ Describe 'PowerShell adapter resource tests' {
104104
}
105105
}
106106

107-
It 'DSCConfigRoot macro is working when config is from a file' -Skip:(!$IsWindows){
107+
It 'DSCConfigRoot macro is working when config is from a file' {
108108

109109
$yaml = @"
110110
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
@@ -129,7 +129,7 @@ Describe 'PowerShell adapter resource tests' {
129129
$res.results.result.actualState.result.properties.Prop1 | Should -Be $TestDrive
130130
}
131131

132-
It 'DSC_CONFIG_ROOT env var is cwd when config is piped from stdin' -Skip:(!$IsWindows){
132+
It 'DSC_CONFIG_ROOT env var is cwd when config is piped from stdin' {
133133

134134
$yaml = @"
135135
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,47 @@ Describe 'PowerShell adapter resource tests' {
2323
Remove-Item -Force -ea SilentlyContinue -Path $cacheFilePath
2424
}
2525

26-
It 'Discovery includes class-based resources' -Skip:(!$IsWindows){
26+
It 'Discovery includes class-based resources' {
2727

2828
$r = dsc resource list * -a Microsoft.DSC/PowerShell
2929
$LASTEXITCODE | Should -Be 0
3030
$resources = $r | ConvertFrom-Json
3131
($resources | ? {$_.Type -eq 'TestClassResource/TestClassResource'}).Count | Should -Be 1
3232
}
3333

34-
It 'Get works on class-based resource' -Skip:(!$IsWindows){
34+
It 'Get works on class-based resource' {
3535

3636
$r = "{'Name':'TestClassResource1'}" | dsc resource get -r 'TestClassResource/TestClassResource'
3737
$LASTEXITCODE | Should -Be 0
3838
$res = $r | ConvertFrom-Json
3939
$res.actualState.result.properties.Prop1 | Should -BeExactly 'ValueForProp1'
4040
}
4141

42-
It 'Get uses enum names on class-based resource' -Skip:(!$IsWindows){
42+
It 'Get uses enum names on class-based resource' {
4343

4444
$r = "{'Name':'TestClassResource1'}" | dsc resource get -r 'TestClassResource/TestClassResource'
4545
$LASTEXITCODE | Should -Be 0
4646
$res = $r | ConvertFrom-Json
4747
$res.actualState.result.properties.EnumProp | Should -BeExactly 'Expected'
4848
}
4949

50-
It 'Test works on class-based resource' -Skip:(!$IsWindows){
50+
It 'Test works on class-based resource' {
5151

5252
$r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1'}" | dsc resource test -r 'TestClassResource/TestClassResource'
5353
$LASTEXITCODE | Should -Be 0
5454
$res = $r | ConvertFrom-Json
5555
$res.actualState.result.properties.InDesiredState | Should -Be $True
5656
}
5757

58-
It 'Set works on class-based resource' -Skip:(!$IsWindows){
58+
It 'Set works on class-based resource' {
5959

6060
$r = "{'Name':'TestClassResource1','Prop1':'ValueForProp1'}" | dsc resource set -r 'TestClassResource/TestClassResource'
6161
$LASTEXITCODE | Should -Be 0
6262
$res = $r | ConvertFrom-Json
6363
$res.afterState.result | Should -Not -BeNull
6464
}
6565

66-
It 'Export works on PS class-based resource' -Skip:(!$IsWindows){
66+
It 'Export works on PS class-based resource' {
6767

6868
$r = dsc resource export -r TestClassResource/TestClassResource
6969
$LASTEXITCODE | Should -Be 0
@@ -73,7 +73,7 @@ Describe 'PowerShell adapter resource tests' {
7373
$res.resources[0].properties.result[0].Prop1 | Should -Be "Property of object1"
7474
}
7575

76-
It 'Get --all works on PS class-based resource' -Skip:(!$IsWindows){
76+
It 'Get --all works on PS class-based resource' {
7777

7878
$r = dsc resource get --all -r TestClassResource/TestClassResource
7979
$LASTEXITCODE | Should -Be 0

powershell-adapter/psDscAdapter/powershell.resource.ps1

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ param(
99
[string]$jsonInput = '@{}'
1010
)
1111

12+
function Write-DscTrace {
13+
param(
14+
[Parameter(Mandatory = $false)]
15+
[ValidateSet('Error', 'Warn', 'Info', 'Debug', 'Trace')]
16+
[string]$Operation = 'Debug',
17+
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
18+
[string]$Message
19+
)
20+
21+
$trace = @{$Operation = $Message } | ConvertTo-Json -Compress
22+
$host.ui.WriteErrorLine($trace)
23+
}
24+
25+
# Adding some debug info to STDERR
26+
'PSVersion=' + $PSVersionTable.PSVersion.ToString() | Write-DscTrace
27+
'PSPath=' + $PSHome | Write-DscTrace
28+
'PSModulePath=' + $env:PSModulePath | Write-DscTrace
29+
1230
if ('Validate' -ne $Operation) {
1331
# write $jsonInput to STDERR for debugging
1432
$trace = @{'Debug' = 'jsonInput=' + $jsonInput } | ConvertTo-Json -Compress
@@ -21,7 +39,6 @@ if ('Validate' -ne $Operation) {
2139
else {
2240
$psDscAdapter = Import-Module "$PSScriptRoot/psDscAdapter.psd1" -Force -PassThru
2341
}
24-
2542

2643
# initialize OUTPUT as array
2744
$result = [System.Collections.Generic.List[Object]]::new()
@@ -50,6 +67,7 @@ switch ($Operation) {
5067
$DscResourceInfo = $dscResource.DscResourceInfo
5168

5269
# Provide a way for existing resources to specify their capabilities, or default to Get, Set, Test
70+
# TODO: for perf, it is better to take capabilities from psd1 in Invoke-DscCacheRefresh, not by extra call to Get-Module
5371
if ($DscResourceInfo.ModuleName) {
5472
$module = Get-Module -Name $DscResourceInfo.ModuleName -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
5573
if ($module.PrivateData.PSData.DscCapabilities) {
@@ -161,14 +179,3 @@ class resourceOutput {
161179
[string] $requireAdapter
162180
[string] $description
163181
}
164-
165-
# Adding some debug info to STDERR
166-
$trace = @{'Debug' = 'PSVersion=' + $PSVersionTable.PSVersion.ToString() } | ConvertTo-Json -Compress
167-
$host.ui.WriteErrorLine($trace)
168-
$trace = @{'Debug' = 'PSPath=' + $PSHome } | ConvertTo-Json -Compress
169-
$host.ui.WriteErrorLine($trace)
170-
$m = Get-Command 'Get-DscResource'
171-
$trace = @{'Debug' = 'Module=' + $m.Source.ToString() } | ConvertTo-Json -Compress
172-
$host.ui.WriteErrorLine($trace)
173-
$trace = @{'Debug' = 'PSModulePath=' + $env:PSModulePath } | ConvertTo-Json -Compress
174-
$host.ui.WriteErrorLine($trace)

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ function FindAndParseResourceDefinitions
7373
[System.Management.Automation.Language.Token[]] $tokens = $null
7474
[System.Management.Automation.Language.ParseError[]] $errors = $null
7575
$ast = [System.Management.Automation.Language.Parser]::ParseFile($filePath, [ref]$tokens, [ref]$errors)
76+
foreach($e in $errors)
77+
{
78+
$e | Out-String | Write-DscTrace -Operation Error
79+
}
80+
7681
$resourceDefinitions = $ast.FindAll(
7782
{
7883
$typeAst = $args[0] -as [System.Management.Automation.Language.TypeDefinitionAst]

0 commit comments

Comments
 (0)