Skip to content

Commit 7d33993

Browse files
Export-DbaCredential.Tests - Add EnableException to Context BeforeAll blocks
When Export-DbaCredential fails during test setup (e.g., connection reset), the test continued and failed on Get-Content with a misleading "file not found" error. Adding EnableException ensures setup failures throw immediately with the actual error message. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b87f095 commit 7d33993

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

tests/Export-DbaCredential.Tests.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Describe $CommandName -Tag IntegrationTests {
131131

132132
Context "Should export all credentials" {
133133
BeforeAll {
134-
$exportFile = Export-DbaCredential -SqlInstance $TestConfig.InstanceSingle
134+
$exportFile = Export-DbaCredential -SqlInstance $TestConfig.InstanceSingle -EnableException
135135
$exportResults = Get-Content -Path $exportFile -Raw
136136
}
137137

@@ -156,9 +156,10 @@ Describe $CommandName -Tag IntegrationTests {
156156
BeforeAll {
157157
$specificFilePath = "$env:USERPROFILE\Documents\dbatoolsci_credential.sql"
158158
$splatExportSpecific = @{
159-
SqlInstance = $TestConfig.InstanceSingle
160-
Identity = $captainCredIdentity
161-
FilePath = $specificFilePath
159+
SqlInstance = $TestConfig.InstanceSingle
160+
Identity = $captainCredIdentity
161+
FilePath = $specificFilePath
162+
EnableException = $true
162163
}
163164
$null = Export-DbaCredential @splatExportSpecific
164165
$specificResults = Get-Content -Path $specificFilePath
@@ -181,10 +182,11 @@ Describe $CommandName -Tag IntegrationTests {
181182
BeforeAll {
182183
$appendFilePath = "$env:USERPROFILE\Documents\dbatoolsci_credential.sql"
183184
$splatExportAppend = @{
184-
SqlInstance = $TestConfig.InstanceSingle
185-
Identity = $hulkCredIdentity
186-
FilePath = $appendFilePath
187-
Append = $true
185+
SqlInstance = $TestConfig.InstanceSingle
186+
Identity = $hulkCredIdentity
187+
FilePath = $appendFilePath
188+
Append = $true
189+
EnableException = $true
188190
}
189191
$null = Export-DbaCredential @splatExportAppend
190192
$appendResults = Get-Content -Path $appendFilePath
@@ -211,6 +213,7 @@ Describe $CommandName -Tag IntegrationTests {
211213
Identity = $captainCredIdentity
212214
FilePath = $excludePasswordFilePath
213215
ExcludePassword = $true
216+
EnableException = $true
214217
}
215218
$null = Export-DbaCredential @splatExportNoPassword
216219
$excludePasswordResults = Get-Content -Path $excludePasswordFilePath

0 commit comments

Comments
 (0)