Skip to content

Commit 4a4b5d6

Browse files
committed
Add cleanup logic for existing snapshots in New-SqlDscDatabaseSnapshot integration tests
1 parent 3cf2e5a commit 4a4b5d6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/Integration/Commands/New-SqlDscDatabaseSnapshot.Integration.Tests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ Describe 'New-SqlDscDatabaseSnapshot' -Tag @('Integration_SQL2017', 'Integration
7979
}
8080

8181
Context 'When creating a database snapshot using ServerObject parameter set' {
82+
AfterEach {
83+
# Clean up snapshot created in this context to avoid file conflicts
84+
$existingSnapshot = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testSnapshotName -ErrorAction 'SilentlyContinue'
85+
86+
if ($existingSnapshot)
87+
{
88+
$null = Remove-SqlDscDatabase -DatabaseObject $existingSnapshot -Force -ErrorAction 'Stop'
89+
}
90+
}
91+
8292
It 'Should create a database snapshot successfully with minimal parameters' {
8393
$result = New-SqlDscDatabaseSnapshot -ServerObject $script:serverObject -Name $script:testSnapshotName -DatabaseName $script:persistentSourceDatabase -Force -ErrorAction 'Stop'
8494

@@ -94,6 +104,10 @@ Describe 'New-SqlDscDatabaseSnapshot' -Tag @('Integration_SQL2017', 'Integration
94104
}
95105

96106
It 'Should throw error when trying to create a snapshot that already exists' {
107+
# First create the snapshot
108+
$null = New-SqlDscDatabaseSnapshot -ServerObject $script:serverObject -Name $script:testSnapshotName -DatabaseName $script:persistentSourceDatabase -Force -ErrorAction 'Stop'
109+
110+
# Then try to create it again - should throw
97111
{ New-SqlDscDatabaseSnapshot -ServerObject $script:serverObject -Name $script:testSnapshotName -DatabaseName $script:persistentSourceDatabase -Force -ErrorAction 'Stop' } |
98112
Should -Throw
99113
}

0 commit comments

Comments
 (0)