Skip to content

Commit 4bece0e

Browse files
Some more test fixes to support remote instances (#10060)
1 parent 548bdc5 commit 4bece0e

26 files changed

Lines changed: 126 additions & 94 deletions

public/Get-DbaRandomizedValue.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ function Get-DbaRandomizedValue {
102102
Will generate a number between -2147483648 and 2147483647
103103
104104
.EXAMPLE
105-
Get-DbaRandomizedValue -RandomizerSubType Zipcode
105+
Get-DbaRandomizedValue -RandomizerType Address -RandomizerSubType Zipcode
106106
107107
Generates a random zipcode
108108
109109
.EXAMPLE
110-
Get-DbaRandomizedValue -RandomizerSubType Zipcode -Format "#### ##"
110+
Get-DbaRandomizedValue -RandomizerType Address -RandomizerSubType Zipcode -Format "#### ##"
111111
112112
Generates a random zipcode like "1234 56"
113113

tests/ConvertTo-DbaXESession.Tests.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ Describe $CommandName -Tag IntegrationTests -Skip:$env:appveyor {
2929
# We want to run all commands in the BeforeAll block with EnableException to ensure that the test fails if the setup fails.
3030
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
3131

32+
$tracePath = "$($TestConfig.Temp)\$CommandName-$(Get-Random)"
33+
$null = New-Item -Path $tracePath -ItemType Directory
34+
3235
$sql = @"
3336
-- Create a Queue
3437
declare @rc int
3538
declare @TraceID int
3639
declare @maxfilesize bigint
3740
set @maxfilesize = 5
38-
exec @rc = sp_trace_create @TraceID output, 0, N'C:\windows\temp\temptrace', @maxfilesize, NULL
41+
exec @rc = sp_trace_create @TraceID output, 0, N'$tracePath\temptrace', @maxfilesize, NULL
3942
4043
-- Set the events
4144
declare @on bit
@@ -133,7 +136,7 @@ select TraceID=@TraceID
133136
Id = $traceid
134137
}
135138
$null = Remove-DbaTrace @splatRemoveTrace
136-
Remove-Item C:\windows\temp\temptrace.trc -ErrorAction SilentlyContinue
139+
Remove-Item -Path $tracePath -Recurse
137140

138141
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
139142
}

tests/Copy-DbaDatabase.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ Describe $CommandName -Tag IntegrationTests {
592592

593593
$sourceDb = Get-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $offlineTestDb
594594
$sourceDb.Status | Should -BeLike "*Offline*"
595+
596+
# Set database online again to be able to remove the files on remove of database
597+
$null = Set-DbaDbState -SqlInstance $TestConfig.instance2 -Database $offlineTestDb -Online
595598
}
596599
}
597600

tests/Copy-DbaLogin.Tests.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ Describe $CommandName -Tag IntegrationTests {
9191
$null = Invoke-DbaQuery -SqlInstance $instance -Database tempdb -Query $dropTableQuery
9292
}
9393

94-
$null = Remove-DbaLogin -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Login 'claudio', 'port', 'tester'
95-
9694
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
9795
}
9896

tests/Export-DbaInstance.Tests.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ Describe $CommandName -Tag IntegrationTests {
9090
$null = Invoke-DbaQuery -SqlInstance $testServer -Database master -Query "CREATE TRIGGER [create_database_$random] ON ALL SERVER FOR CREATE_DATABASE AS SELECT 1"
9191

9292
# database restore scripts
93-
$backupdir = Join-Path $server.BackupDirectory $dbName
94-
if (-not (Test-Path $backupdir -PathType Container)) {
95-
$null = New-Item -Path $backupdir -ItemType Container
96-
}
93+
$backupdir = "$($TestConfig.Temp)\$CommandName-$(Get-Random)"
94+
$null = New-Item -Path $backupdir -ItemType Directory
9795
New-DbaDatabase -SqlInstance $testServer -Name $dbName
9896
Backup-DbaDatabase -SqlInstance $testServer -Database $dbName -BackupDirectory $backupdir
9997

@@ -174,7 +172,7 @@ Describe $CommandName -Tag IntegrationTests {
174172
$null = Invoke-DbaQuery -SqlInstance $testServer -Database master -Query "DROP TRIGGER [create_database_$random] ON ALL SERVER"
175173

176174
# database restore scripts
177-
Remove-Item -Path $backupdir -Recurse -Force -ErrorAction SilentlyContinue
175+
Remove-Item -Path $backupdir -Recurse
178176

179177
# database audit
180178
$null = Invoke-DbaQuery -SqlInstance $testServer -Database $dbName -Query "ALTER DATABASE AUDIT SPECIFICATION [DatabaseAuditSpecification_$random] WITH (STATE = OFF); DROP DATABASE AUDIT SPECIFICATION [DatabaseAuditSpecification_$random]"

tests/Get-DbaDbOrphanUser.Tests.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ CREATE LOGIN [dbatoolsci_orphan3] WITH PASSWORD = N'password3', CHECK_EXPIRATION
3535
CREATE DATABASE dbatoolsci_orphan;
3636
"@
3737
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance1
38-
$null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force
39-
$null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan
4038
$null = Invoke-DbaQuery -SqlInstance $server -Query $loginsq
4139
$usersq = @"
4240
CREATE USER [dbatoolsci_orphan1] FROM LOGIN [dbatoolsci_orphan1];
@@ -56,8 +54,8 @@ CREATE USER [dbatoolsci_orphan3] FROM LOGIN [dbatoolsci_orphan3];
5654
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
5755

5856
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance1
59-
$null = Remove-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 -Force -ErrorAction SilentlyContinue
60-
$null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan -ErrorAction SilentlyContinue
57+
$null = Get-DbaLogin -SqlInstance $server -Login dbatoolsci_orphan1, dbatoolsci_orphan2, dbatoolsci_orphan3 | Remove-DbaLogin -Force
58+
$null = Remove-DbaDatabase -SqlInstance $server -Database dbatoolsci_orphan
6159

6260
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
6361
}

tests/Get-DbaRandomizedValue.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Describe $CommandName -Tag IntegrationTests {
4747
It "Should return a random address zipcode" -Skip:$env:AppVeyor {
4848
# Skip It on AppVeyor because: Method invocation failed because [Bogus.DataSets.Name] does not contain a method named 'ZipCode'.
4949

50-
$result = Get-DbaRandomizedValue -RandomizerSubType Zipcode -Format "#####"
50+
$result = Get-DbaRandomizedValue -RandomizerType Address -RandomizerSubType Zipcode -Format "#####"
5151

5252
$result.Length | Should -Be 5
5353
}

tests/Grant-DbaAgPermission.Tests.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Describe $CommandName -Tag IntegrationTests {
5353
$null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agName
5454
$null = Get-DbaEndpoint -SqlInstance $TestConfig.instance3 -Type DatabaseMirroring | Remove-DbaEndpoint
5555
$null = Remove-DbaLogin -SqlInstance $TestConfig.instance3 -Login "claudio", "port", "tester"
56-
$null = Remove-DbaLogin -SqlInstance $TestConfig.instance3 -Login "claudio", "port", "tester"
5756

5857
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
5958
}

tests/New-DbaDacOption.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Describe $CommandName -Tag UnitTests {
2323
}
2424
Describe $CommandName -Tag IntegrationTests {
2525
BeforeAll {
26-
$publishProfile = New-DbaDacProfile -SqlInstance $TestConfig.instance1 -Database whatever -Path C:\Temp
26+
$publishProfile = New-DbaDacProfile -SqlInstance $TestConfig.instance1 -Database whatever -Path $TestConfig.Temp -EnableException
2727
}
2828

2929
AfterAll {

tests/New-DbaDacPackage.Tests.ps1

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ LEFT JOIN dbo.TestTable2 t2 ON t1.Id = t2.TestTable1Id;
100100
It "Builds a DACPAC from a directory with SQL files recursively" {
101101
$outputDacpac = "$testFolder\output-recursive.dacpac"
102102
$splatBuildRecursive = @{
103-
Path = $sqlSourcePath
104-
OutputPath = $outputDacpac
105-
Recursive = $true
106-
DatabaseName = "TestDatabase"
103+
Path = $sqlSourcePath
104+
OutputPath = $outputDacpac
105+
Recursive = $true
106+
DatabaseName = "TestDatabase"
107+
WarningAction = "SilentlyContinue"
107108
}
108109
$result = New-DbaDacPackage @splatBuildRecursive
109110

111+
$WarnVar | Should -BeLike "*Skipping empty file: *\Schema\EmptyFile.sql"
110112
$result | Should -Not -BeNullOrEmpty
111113
$result.Success | Should -BeTrue
112114
$result.Path | Should -Be $outputDacpac
@@ -125,9 +127,11 @@ LEFT JOIN dbo.TestTable2 t2 ON t1.Id = t2.TestTable1Id;
125127
DatabaseName = "VersionedDB"
126128
DacVersion = "2.1.0.0"
127129
DacDescription = "Test DACPAC with version"
130+
WarningAction = "SilentlyContinue"
128131
}
129132
$result = New-DbaDacPackage @splatBuildVersioned
130133

134+
$WarnVar | Should -BeLike "*Skipping empty file: *\Schema\EmptyFile.sql"
131135
$result | Should -Not -BeNullOrEmpty
132136
$result.Success | Should -BeTrue
133137
$result.Version | Should -Be "2.1.0.0"
@@ -142,9 +146,11 @@ LEFT JOIN dbo.TestTable2 t2 ON t1.Id = t2.TestTable1Id;
142146
Recursive = $true
143147
DatabaseName = "Sql2017DB"
144148
SqlServerVersion = "Sql140"
149+
WarningAction = "SilentlyContinue"
145150
}
146151
$result = New-DbaDacPackage @splatBuildTargeted
147152

153+
$WarnVar | Should -BeLike "*Skipping empty file: *\Schema\EmptyFile.sql"
148154
$result | Should -Not -BeNullOrEmpty
149155
$result.Success | Should -BeTrue
150156
Test-Path $outputDacpac | Should -BeTrue
@@ -153,13 +159,15 @@ LEFT JOIN dbo.TestTable2 t2 ON t1.Id = t2.TestTable1Id;
153159
It "Builds from non-recursive directory scan" {
154160
$outputDacpac = "$testFolder\output-nonrecursive.dacpac"
155161
$splatBuildNonRecursive = @{
156-
Path = $sqlSourcePath
157-
OutputPath = $outputDacpac
158-
DatabaseName = "NonRecursiveDB"
162+
Path = $sqlSourcePath
163+
OutputPath = $outputDacpac
164+
DatabaseName = "NonRecursiveDB"
165+
WarningAction = "SilentlyContinue"
159166
}
160167
$result = New-DbaDacPackage @splatBuildNonRecursive
161168

162169
# Non-recursive should only find the EmptyFile.sql in the root
170+
$WarnVar | Should -BeLike "*Skipping empty file: *\Schema\EmptyFile.sql"
163171
$result | Should -Not -BeNullOrEmpty
164172
# May succeed or fail depending on if there are valid SQL files in root
165173
}
@@ -169,13 +177,15 @@ LEFT JOIN dbo.TestTable2 t2 ON t1.Id = t2.TestTable1Id;
169177
It "Returns object with Path property for pipeline compatibility" {
170178
$outputDacpac = "$testFolder\output-pipeline.dacpac"
171179
$splatBuildPipeline = @{
172-
Path = $sqlSourcePath
173-
OutputPath = $outputDacpac
174-
Recursive = $true
175-
DatabaseName = "PipelineDB"
180+
Path = $sqlSourcePath
181+
OutputPath = $outputDacpac
182+
Recursive = $true
183+
DatabaseName = "PipelineDB"
184+
WarningAction = "SilentlyContinue"
176185
}
177186
$result = New-DbaDacPackage @splatBuildPipeline
178187

188+
$WarnVar | Should -BeLike "*Skipping empty file: *\Schema\EmptyFile.sql"
179189
$result | Should -Not -BeNullOrEmpty
180190
$result.Path | Should -Not -BeNullOrEmpty
181191
$result.Database | Should -Not -BeNullOrEmpty
@@ -199,13 +209,15 @@ LEFT JOIN dbo.TestTable2 t2 ON t1.Id = t2.TestTable1Id;
199209
It "Built DACPAC can be loaded by DacFx" {
200210
$outputDacpac = "$testFolder\output-loadtest.dacpac"
201211
$splatBuildLoadTest = @{
202-
Path = $sqlSourcePath
203-
OutputPath = $outputDacpac
204-
Recursive = $true
205-
DatabaseName = "LoadTestDB"
212+
Path = $sqlSourcePath
213+
OutputPath = $outputDacpac
214+
Recursive = $true
215+
DatabaseName = "LoadTestDB"
216+
WarningAction = "SilentlyContinue"
206217
}
207218
$result = New-DbaDacPackage @splatBuildLoadTest
208219

220+
$WarnVar | Should -BeLike "*Skipping empty file: *\Schema\EmptyFile.sql"
209221
$result.Success | Should -BeTrue
210222

211223
# Verify the DACPAC can be loaded

0 commit comments

Comments
 (0)