Skip to content

Commit 032ef21

Browse files
committed
Refactor integration tests to improve error handling and output for DSC executable failures
1 parent 61e5c18 commit 032ef21

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tests/Integration/Resources/DSCv3_DebugDscEngine.Integration.Tests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,12 @@ Describe "$($script:dscResourceFriendlyName)_Integration" -Tag @('Integration_SQ
208208
$result = dsc --trace-level trace resource set --resource SqlServerDsc/DebugDscEngine --output-format json --input ($desiredParameters | ConvertTo-Json -Compress) | ConvertFrom-Json
209209

210210
$dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
211-
Write-Verbose -Message "DSCv3 exit code: $($dscExitCode | Out-String)" -Verbose
212-
Write-Verbose -Message "DSCv3 exit code type: $($dscExitCode.GetType().FullName | Out-String)" -Verbose
213-
214211

215212
if ($dscExitCode -ne 0)
216213
{
217214
throw ('DSC executable failed with exit code {0}.' -f $dscExitCode)
218215
}
219216

220-
Write-Verbose -Message "DSCv3 exit code: $($dscExitCode | Out-String)" -Verbose
221217
Write-Verbose -Message "Result (all):`n$($result | ConvertTo-Json | Out-String)" -Verbose
222218
}
223219
}
@@ -229,18 +225,18 @@ Describe "$($script:dscResourceFriendlyName)_Integration" -Tag @('Integration_SQ
229225
MandatoryProperty = 'TestMandatoryValue'
230226
}
231227

228+
$mockExpectedErrorCode = 2
229+
232230
{
233231
$result = dsc --trace-level trace resource get --resource SqlServerDsc/DebugDscEngine --output-format json --input ($desiredParameters | ConvertTo-Json -Compress) | ConvertFrom-Json
234232

235233
$dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
236234

237-
Write-Verbose -Message "DSCv3 exit code: $($dscExitCode | Out-String)" -Verbose
238-
239235
if ($dscExitCode -ne 0)
240236
{
241237
throw ('DSC executable failed with exit code {0}.' -f $dscExitCode)
242238
}
243-
} | Should -Throw -ExpectedMessage 'MOCK ERROR: KeyProperty is required'
239+
} | Should -Throw -ExpectedMessage ('DSC executable failed with exit code {0}.' -f $mockExpectedErrorCode)
244240
}
245241

246242
It 'Should fail when MandatoryProperty is empty' {
@@ -249,18 +245,18 @@ Describe "$($script:dscResourceFriendlyName)_Integration" -Tag @('Integration_SQ
249245
MandatoryProperty = ''
250246
}
251247

248+
$mockExpectedErrorCode = 2
249+
252250
{
253251
$result = dsc --trace-level trace resource get --resource SqlServerDsc/DebugDscEngine --output-format json --input ($desiredParameters | ConvertTo-Json -Compress) | ConvertFrom-Json
254252

255253
$dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
256254

257-
Write-Verbose -Message "DSCv3 exit code: $($dscExitCode | Out-String)" -Verbose
258-
259255
if ($dscExitCode -ne 0)
260256
{
261257
throw ('DSC executable failed with exit code {0}.' -f $dscExitCode)
262258
}
263-
} | Should -Throw
259+
} | Should -Throw -ExpectedMessage ('DSC executable failed with exit code {0}.' -f $mockExpectedErrorCode)
264260
}
265261
}
266262

@@ -287,10 +283,14 @@ Describe "$($script:dscResourceFriendlyName)_Integration" -Tag @('Integration_SQ
287283

288284
$dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
289285

286+
Write-Verbose -Message "DSCv3 exit code: $($dscExitCode | Out-String)" -Verbose
287+
290288
if ($dscExitCode -ne 0)
291289
{
292290
throw ('DSC executable failed with exit code {0}.' -f $dscExitCode)
293291
}
292+
293+
Write-Verbose -Message "Result (all):`n$($result | ConvertTo-Json | Out-String)" -Verbose
294294
}
295295
}
296296
}

0 commit comments

Comments
 (0)