@@ -60,23 +60,92 @@ Describe 'dsc config get tests' {
6060 $config_yaml = @"
6161 `$ schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
6262 resources:
63- - name: Echo
63+ - name: Echo 1
6464 type: Microsoft.DSC.Debug/Echo
6565 properties:
6666 output: hello
67+ - name: Echo 2
68+ type: Microsoft.DSC.Debug/Echo
69+ properties:
70+ output: world
6771"@
6872 $config_yaml | dsc -- progress- format json config get -f - 2> $TestDrive / ErrorStream.txt
6973 $LASTEXITCODE | Should - Be 0
7074 $lines = Get-Content $TestDrive / ErrorStream.txt
71- $ProgressMessagesFound = $False
75+ $ProgressMessagesFound = $false
76+ $InstanceOneFound = $false
77+ $InstanceTwoFound = $false
7278 foreach ($line in $lines ) {
7379 $jp = $line | ConvertFrom-Json
7480 if ($jp.activity ) { # if line is a progress message
75- $jp.percent_complete | Should - BeIn (0 .. 100 )
76- $ProgressMessagesFound = $True
81+ $jp.id | Should -Not - BeNullOrEmpty
82+ $jp.totalItems | Should -Not - BeNullOrEmpty
83+ $jp.completedItems | Should -Not - BeNullOrEmpty
84+ $ProgressMessagesFound = $true
85+ }
86+
87+ if ($null -ne $jp.result -and $jp.resourceType -eq ' Microsoft.DSC.Debug/Echo' ) {
88+ if ($jp.resourceName -eq ' Echo 1' ) {
89+ $InstanceOneFound = $true
90+ $jp.result.actualState.output | Should - BeExactly ' hello'
91+ } elseif ($jp.resourceName -eq ' Echo 2' ) {
92+ $InstanceTwoFound = $true
93+ $jp.result.actualState.output | Should - BeExactly ' world'
94+ }
95+ }
96+ }
97+ $ProgressMessagesFound | Should - BeTrue
98+ $InstanceOneFound | Should - BeTrue
99+ $InstanceTwoFound | Should - BeTrue
100+ }
101+
102+ It ' json progress returns correctly for failed resource' {
103+ $config_yaml = @'
104+ $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
105+ resources:
106+ - name: Echo 1
107+ type: Microsoft.DSC.Debug/Echo
108+ properties:
109+ output: hello
110+ - name: ErrorTest
111+ type: Test/ExitCode
112+ properties:
113+ exitCode: 8
114+ '@
115+ dsc -- progress- format json -- trace-format json config get - i $config_yaml 2> $TestDrive / ErrorStream.txt
116+ $LASTEXITCODE | Should - Be 2
117+ $lines = Get-Content $TestDrive / ErrorStream.txt
118+ $ProgressMessagesFound = $false
119+ $InstanceOneFound = $false
120+ $InstanceTwoFound = $false
121+ foreach ($line in $lines ) {
122+ $jp = $line | ConvertFrom-Json
123+ if ($jp.activity ) { # if line is a progress message
124+ $jp.id | Should -Not - BeNullOrEmpty
125+ $jp.totalItems | Should -Not - BeNullOrEmpty
126+ $jp.completedItems | Should -Not - BeNullOrEmpty
127+ $ProgressMessagesFound = $true
128+ }
129+
130+ if ($null -ne $jp.result -and $jp.resourceType -eq ' Microsoft.DSC.Debug/Echo' ) {
131+ if ($jp.resourceName -eq ' Echo 1' ) {
132+ $InstanceOneFound = $true
133+ $jp.result.actualState.output | Should - BeExactly ' hello'
134+ $jp.failed | Should - BeNullOrEmpty
135+ }
136+ }
137+ elseif ($null -ne $jp.failure -and $jp.resourceType -eq ' Test/ExitCode' ) {
138+ if ($jp.resourceName -eq ' ErrorTest' ) {
139+ $InstanceTwoFound = $true
140+ $jp.result | Should - BeNullOrEmpty
141+ $jp.failure.exitCode | Should - Be 8
142+ $jp.failure.message | Should -Not - BeNullOrEmpty
143+ }
77144 }
78145 }
79146 $ProgressMessagesFound | Should - BeTrue
147+ $InstanceOneFound | Should - BeTrue
148+ $InstanceTwoFound | Should - BeTrue
80149 }
81150
82151 It ' contentVersion is ignored' {
0 commit comments