Skip to content

Commit 3b69a91

Browse files
committed
Add -ErrorAction 'Stop' to various commands in PostInstallationConfiguration integration tests for improved error handling
1 parent e111b04 commit 3b69a91

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/Integration/Commands/PostInstallationConfiguration.Integration.Tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Describe 'PostInstallationConfiguration' -Tag @('Integration_SQL2017', 'Integrat
6868
CertStoreLocation = 'cert:\LocalMachine\My'
6969
}
7070

71-
$script:certificate = New-SelfSignedCertificate @certificateParams
71+
$script:certificate = New-SelfSignedCertificate @certificateParams -ErrorAction 'Stop'
7272

7373
$script:certificate | Should -Not -BeNullOrEmpty
7474
$script:certificate.Thumbprint | Should -Not -BeNullOrEmpty
@@ -107,17 +107,17 @@ Describe 'PostInstallationConfiguration' -Tag @('Integration_SQL2017', 'Integrat
107107
Test-Path -Path $privateKeyFile | Should -BeTrue
108108

109109
# Grant read permission to the SQL Server service account
110-
$acl = Get-Acl -Path $privateKeyFile
110+
$acl = Get-Acl -Path $privateKeyFile -ErrorAction 'Stop'
111111
$accessRule = [System.Security.AccessControl.FileSystemAccessRule]::new(
112112
$script:serviceAccountName,
113113
[System.Security.AccessControl.FileSystemRights]::Read,
114114
[System.Security.AccessControl.AccessControlType]::Allow
115115
)
116116
$acl.AddAccessRule($accessRule)
117-
Set-Acl -Path $privateKeyFile -AclObject $acl
117+
Set-Acl -Path $privateKeyFile -AclObject $acl -ErrorAction 'Stop'
118118

119119
# Verify permission was granted
120-
$updatedAcl = Get-Acl -Path $privateKeyFile
120+
$updatedAcl = Get-Acl -Path $privateKeyFile -ErrorAction 'Stop'
121121
$serviceAccountAccess = $updatedAcl.Access | Where-Object -FilterScript {
122122
$_.IdentityReference -like "*$script:serviceAccountName*" -and $_.FileSystemRights -match 'Read'
123123
}
@@ -174,7 +174,7 @@ Describe 'PostInstallationConfiguration' -Tag @('Integration_SQL2017', 'Integrat
174174
$serverObject.Status.ToString() | Should -Match '^Online$'
175175

176176
# Clean up
177-
Disconnect-SqlDscDatabaseEngine -ServerObject $serverObject
177+
Disconnect-SqlDscDatabaseEngine -ServerObject $serverObject -ErrorAction 'Stop'
178178
}
179179

180180
It 'Should verify the connection is using encryption via DMV query' {
@@ -204,7 +204,7 @@ WHERE session_id = @@SPID
204204
$result.Tables[0].Rows[0]['encrypt_option'] | Should -Be 'TRUE'
205205

206206
# Clean up
207-
Disconnect-SqlDscDatabaseEngine -ServerObject $serverObject
207+
Disconnect-SqlDscDatabaseEngine -ServerObject $serverObject -ErrorAction 'Stop'
208208

209209
Write-Verbose -Message "Verified encrypted connection using sys.dm_exec_connections DMV" -Verbose
210210
Write-Verbose -Message "SSL certificate successfully configured for SQL Server instance $script:instanceName" -Verbose

0 commit comments

Comments
 (0)