@@ -174,4 +174,85 @@ Describe 'Tests for PSScript resource' {
174
174
$LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
175
175
$result.InDesiredState | Should - BeTrue
176
176
}
177
+
178
+ It ' Write-Warning shows up as warn traces for <resourceType>' - TestCases $testCases {
179
+ param ($resourceType )
180
+
181
+ $yaml = @'
182
+ GetScript: |
183
+ Write-Warning "This is a warning"
184
+ '@
185
+
186
+ $result = dsc resource get - r $resourceType - i $yaml 2> $TestDrive / error.txt | ConvertFrom-Json
187
+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
188
+ $result.actualState.output.Count | Should - Be 0 - Because ($result | ConvertTo-Json | Out-String )
189
+ (Get-Content $TestDrive / error.txt - Raw) | Should - BeLike ' *WARN*:*This is a warning*'
190
+ }
191
+
192
+ It ' Write-Error shows up as error traces for <resourceType>' - TestCases $testCases {
193
+ param ($resourceType )
194
+
195
+ $yaml = @'
196
+ GetScript: |
197
+ Write-Error "This is an error"
198
+ '@
199
+
200
+ $result = dsc resource get - r $resourceType - i $yaml 2> $TestDrive / error.txt | ConvertFrom-Json
201
+ $LASTEXITCODE | Should - Be 2 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
202
+ $result.actualState.output.Count | Should - Be 0 - Because ($result | ConvertTo-Json | Out-String )
203
+ (Get-Content $TestDrive / error.txt - Raw) | Should - BeLike ' *ERROR*:*This is an error*'
204
+ }
205
+
206
+ It ' Write-Verbose shows up as info traces for <resourceType>' - TestCases $testCases {
207
+ param ($resourceType )
208
+
209
+ $yaml = @'
210
+ GetScript: |
211
+ Write-Verbose "This is a verbose message"
212
+ '@
213
+ $result = dsc - l info resource get - r $resourceType - i $yaml 2> $TestDrive / error.txt | ConvertFrom-Json
214
+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
215
+ $result.actualState.output.Count | Should - Be 0 - Because ($result | ConvertTo-Json | Out-String )
216
+ (Get-Content $TestDrive / error.txt - Raw) | Should - BeLike ' *INFO*:*This is a verbose message*'
217
+ }
218
+
219
+ It ' Write-Debug shows up as debug traces for <resourceType>' - TestCases $testCases {
220
+ param ($resourceType )
221
+
222
+ $yaml = @'
223
+ GetScript: |
224
+ Write-Debug "This is a debug message"
225
+ '@
226
+ $result = dsc - l debug resource get - r $resourceType - i $yaml 2> $TestDrive / error.txt | ConvertFrom-Json
227
+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
228
+ $result.actualState.output.Count | Should - Be 0 - Because ($result | ConvertTo-Json | Out-String )
229
+ (Get-Content $TestDrive / error.txt - Raw) | Should - BeLike ' *DEBUG*:*This is a debug message*'
230
+ }
231
+
232
+ It ' Write-Information shows up as trace traces for <resourceType>' - TestCases $testCases {
233
+ param ($resourceType )
234
+
235
+ $yaml = @'
236
+ GetScript: |
237
+ $InformationPreference = 'Continue'
238
+ Write-Information "This is an information message"
239
+ '@
240
+ $result = dsc - l trace resource get - r $resourceType - i $yaml 2> $TestDrive / error.txt | ConvertFrom-Json
241
+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
242
+ $result.actualState.output.Count | Should - Be 0 - Because ($result | ConvertTo-Json | Out-String )
243
+ (Get-Content $TestDrive / error.txt - Raw) | Should - BeLike ' *TRACE*:*This is an information message*'
244
+ }
245
+
246
+ It ' A thrown exception results in an error for <resourceType>' - TestCases $testCases {
247
+ param ($resourceType )
248
+
249
+ $yaml = @'
250
+ GetScript: |
251
+ throw "This is an exception"
252
+ '@
253
+ $result = dsc resource get - r $resourceType - i $yaml 2> $TestDrive / error.txt | ConvertFrom-Json
254
+ $LASTEXITCODE | Should - Be 2 - Because (Get-Content $TestDrive / error.txt - Raw | Out-String )
255
+ $result.actualState.output.Count | Should - Be 0 - Because ($result | ConvertTo-Json | Out-String )
256
+ (Get-Content $TestDrive / error.txt - Raw) | Should - BeLike ' *ERROR*:*This is an exception*'
257
+ }
177
258
}
0 commit comments