From da4ada97684aad73b4920798a4cae1949bef57d0 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 21 Jul 2018 10:23:49 +1200 Subject: [PATCH] Check for error correctly in integrationt ests --- ...rCertificateServices.Integration.Tests.ps1 | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Tests/Integration/MSFT_WaitForCertificateServices.Integration.Tests.ps1 b/Tests/Integration/MSFT_WaitForCertificateServices.Integration.Tests.ps1 index e4bcdfe9..29dff5e7 100644 --- a/Tests/Integration/MSFT_WaitForCertificateServices.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_WaitForCertificateServices.Integration.Tests.ps1 @@ -24,6 +24,8 @@ $TestEnvironment = Initialize-TestEnvironment ` -TestType Integration #endregion +Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global + # Using try/finally to always cleanup even if something awful happens. try { @@ -51,16 +53,16 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - CAServerFQDN = $caServerFQDN - CARootName = $caRootName + NodeName = 'localhost' + CAServerFQDN = $caServerFQDN + CARootName = $caRootName RetryIntervalSeconds = 1 - RetryCount = 2 + RetryCount = 2 } ) } - It 'Should compile and apply the MOF without throwing' { + It 'Should compile and apply the MOF without throwing an exception' { { & "$($script:DSCResourceName)_Config" ` -OutputPath $TestDrive ` @@ -72,7 +74,7 @@ try -Wait ` -Verbose ` -Force ` - -ErrorAction SilentlyContinue + -ErrorAction Stop } | Should -Not -Throw } @@ -100,31 +102,35 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - CAServerFQDN = $caServerFQDN - CARootName = $caRootName + NodeName = 'localhost' + CAServerFQDN = $caServerFQDN + CARootName = $caRootName RetryIntervalSeconds = 1 - RetryCount = 2 + RetryCount = 2 } ) } - It 'Should compile and apply the MOF without throwing' { + It 'Should compile the MOF without throwing an exception' { { & "$($script:DSCResourceName)_Config" ` -OutputPath $TestDrive ` -ConfigurationData $configData - - Start-DscConfiguration ` - -Path $TestDrive ` - -ComputerName localhost ` - -Wait ` - -Verbose ` - -Force ` - -ErrorAction SilentlyContinue } | Should -Not -Throw } + It 'Should apply the MOF throwing an exception' { + { + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop + } | Should -Throw + } + It 'Should be able to call Get-DscConfiguration without throwing' { { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw }