Skip to content

Commit 0cb44a1

Browse files
Compare-DbaDbSchema - Fix test state isolation by exporting empty target DACPAC in BeforeAll
Export the empty target DB to a DACPAC in the shared BeforeAll block before any tests can modify the target DB (via Publish-DbaDacPackage). This prevents the DACPAC-to-DACPAC comparison tests from getting zero differences because the target DB was already populated by the 'Returns no differences' test. (do Compare-DbaDbSchema) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent 830627a commit 0cb44a1

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

tests/Compare-DbaDbSchema.Tests.ps1

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ Describe $CommandName -Tag IntegrationTests {
5858

5959
$sourceDacpac = "$testFolder\$dbSourceName.dacpac"
6060

61+
# Export the empty target DB to a DACPAC now, before any tests modify it.
62+
$splatExportTarget = @{
63+
SqlInstance = $TestConfig.InstanceSingle
64+
Database = $dbTargetName
65+
FilePath = "$testFolder\$dbTargetName.dacpac"
66+
}
67+
$null = Export-DbaDacPackage @splatExportTarget
68+
69+
$emptyTargetDacpac = "$testFolder\$dbTargetName.dacpac"
70+
6171
# We want to run all commands outside of the BeforeAll block without EnableException to be able to test for specific warnings.
6272
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
6373
}
@@ -109,17 +119,6 @@ Describe $CommandName -Tag IntegrationTests {
109119

110120
Context "Compare two DACPAC files" {
111121
It "Returns schema differences between two DACPAC files" {
112-
# Export the empty target as a second DACPAC.
113-
$splatExportTarget = @{
114-
SqlInstance = $TestConfig.InstanceSingle
115-
Database = $dbTargetName
116-
FilePath = "$testFolder\$dbTargetName.dacpac"
117-
}
118-
$null = Export-DbaDacPackage @splatExportTarget
119-
120-
# Create an empty-DB DACPAC to compare against the source DACPAC.
121-
$emptyTargetDacpac = "$testFolder\$dbTargetName.dacpac"
122-
123122
$splatCompare = @{
124123
SourcePath = $sourceDacpac
125124
TargetPath = $emptyTargetDacpac
@@ -132,8 +131,6 @@ Describe $CommandName -Tag IntegrationTests {
132131
}
133132

134133
It "Keeps the report file when -KeepReport is specified" {
135-
$emptyTargetDacpac = "$testFolder\$dbTargetName.dacpac"
136-
137134
$splatCompare = @{
138135
SourcePath = $sourceDacpac
139136
TargetPath = $emptyTargetDacpac

0 commit comments

Comments
 (0)