Skip to content

Commit 67307c2

Browse files
Another round of fixes for tests (#9747)
1 parent fcd7f4c commit 67307c2

27 files changed

+99
-78
lines changed

tests/Add-DbaDbMirrorMonitor.Tests.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ Describe $CommandName -Tag "UnitTests" {
3131
}
3232

3333
Describe $CommandName -Tag "IntegrationTests" {
34-
BeforeAll {
35-
$null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue
36-
}
3734
AfterAll {
3835
$null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue
3936
}

tests/Export-DbaRegServer.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
8686

8787
It "Try to create an invalid file using FilePath" {
8888
$outputFileName = "$newDirectory\dbatoolsci-regsrvr-export-$random.txt"
89-
$results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName
89+
$results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName -WarningAction SilentlyContinue
90+
# TODO: Test for [Export-DbaRegServer] The FilePath specified must end with either .xml or .regsrvr
9091
$results.length | Should -Be 0
9192
}
9293

@@ -99,7 +100,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
99100

100101
It "Ensure the Overwrite param is working" {
101102
$outputFileName = "$newDirectory\dbatoolsci-regsrvr-export-$random.xml"
102-
$results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName
103+
$results = Export-DbaRegServer -SqlInstance $TestConfig.instance2 -FilePath $outputFileName -WarningAction SilentlyContinue
104+
# TODO: Test for [Export-DbaRegServer] Use the -Overwrite parameter if the file C:\temp\539615200\dbatoolsci-regsrvr-export-539615200.xml should be overwritten.
103105
$results -is [System.IO.FileInfo] | Should -Be $true
104106
$results.FullName | Should -Be $outputFileName
105107

tests/Export-DbaScript.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
3232

3333
It "should not accept non-SMO objects" {
3434
$null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo"
35-
$null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction Continue
35+
$null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction SilentlyContinue
3636
$invalid -match "not a SQL Management Object"
3737
}
3838

3939
It "should not accept non-SMO objects" {
4040
$null = Get-DbaDbTable -SqlInstance $TestConfig.instance2 -Database msdb | Select-Object -First 1 | Export-DbaScript -Passthru -BatchSeparator "MakeItSo"
41-
$null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction Continue
41+
$null = [pscustomobject]@{ Invalid = $true } | Export-DbaScript -WarningVariable invalid -WarningAction SilentlyContinue
4242
$invalid -match "not a SQL Management Object"
4343
}
4444
It "should not append when using NoPrefix (#7455)" {

tests/Find-DbaDbUnusedIndex.Tests.ps1

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
2323
Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
2424
Context "Verify basics of the Find-DbaDbUnusedIndex command" {
2525
BeforeAll {
26-
Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex testing connection to $($TestConfig.instance2)"
2726
Test-DbaConnection -SqlInstance $TestConfig.instance2
2827

2928
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
3029

3130
$random = Get-Random
3231
$dbName = "dbatoolsci_$random"
3332

34-
Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex setting up the new database $dbName"
3533
Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false
3634
$newDB = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $dbName
3735

@@ -48,7 +46,6 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
4846
}
4947

5048
AfterAll {
51-
Write-Message -Level Warning -Message "Find-DbaDbUnusedIndex removing the database $dbName"
5249
Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbName -Confirm:$false
5350
}
5451

@@ -61,10 +58,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
6158

6259
foreach ($row in $results) {
6360
if ($row["IndexName"] -eq $indexName) {
64-
Write-Message -Level Debug -Message "$($indexName) was found on $($TestConfig.instance2) in database $($dbName)"
6561
$testSQLinstance = $true
66-
} else {
67-
Write-Message -Level Warning -Message "$($indexName) was not found on $($TestConfig.instance2) in database $($dbName)"
6862
}
6963
}
7064

@@ -87,18 +81,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
8781
} elseif ($results -is [Object[]] -and $results.Count -gt 0) {
8882
$row = $results[0]
8983
} else {
90-
Write-Message -Level Warning -Message "Unexpected results returned from $($SqlInstance): $($results)"
9184
$testSQLinstance = $false
9285
}
9386

9487
if ($null -ne $row) {
9588
[object[]]$columnNamesReturned = @($row | Get-Member -MemberType Property | Select-Object -Property Name | ForEach-Object { $_.Name })
9689

9790
if ( @(Compare-Object -ReferenceObject $expectedColumnArray -DifferenceObject $columnNamesReturned).Count -eq 0 ) {
98-
Write-Message -Level Debug -Message "Columns matched on $($TestConfig.instance2)"
9991
$testSQLinstance = $true
100-
} else {
101-
Write-Message -Level Warning -Message "The columns specified in the expectedColumnList variable do not match these returned columns from $($TestConfig.instance2): $($columnNamesReturned)"
10292
}
10393
}
10494
}

tests/Get-DbaAgDatabase.Tests.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
1515

1616
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
1717
BeforeAll {
18+
$backupPath = "$($TestConfig.Temp)\$CommandName"
19+
$null = New-Item -Path $backupPath -ItemType Directory
20+
1821
$null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue
1922
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance3
2023
$agname = "dbatoolsci_getagdb_agroup"
2124
$dbname = "dbatoolsci_getagdb_agroupdb"
2225
$server.Query("create database $dbname")
23-
$null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase
24-
$null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Type Log
26+
$null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Path $backupPath
27+
$null = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase -Path $backupPath -Type Log
2528
$ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert -UseLastBackup
2629
}
2730
AfterAll {
2831
$null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false
2932
$null = Get-DbaEndpoint -SqlInstance $TestConfig.instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false
3033
$null = Remove-DbaDatabase -SqlInstance $server -Database $dbname -Confirm:$false
34+
Remove-Item -Path $backupPath -Recurse
3135
}
3236
Context "gets ag db" {
3337
It "returns results" {

tests/Get-DbaAgentSchedule.Tests.ps1

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
1515

1616
Describe "$commandname Integration Tests" -Tags "UnitTests" {
1717
BeforeAll {
18-
Write-Message -Level Warning -Message "BeforeAll start: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)"
1918
$server3 = Connect-DbaInstance -SqlInstance $TestConfig.instance3
2019
$server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2
2120

2221
$sqlAgentServer3 = Get-DbaService -ComputerName $server3.ComputerName -InstanceName $server3.DbaInstanceName -Type Agent
23-
Write-Message -Level Warning -Message "The SQL Agent service for instance3 has state=$($sqlAgentServer3.State) and start mode=$($sqlAgentServer3.StartMode)"
24-
2522
$sqlAgentServer2 = Get-DbaService -ComputerName $server2.ComputerName -InstanceName $server2.DbaInstanceName -Type Agent
26-
Write-Message -Level Warning -Message "The SQL Agent service for instance2 has state=$($sqlAgentServer2.State) and start mode=$($sqlAgentServer2.StartMode)"
2723

2824
$null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force
2925
$null = New-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_WeeklyTest -FrequencyType Weekly -FrequencyInterval 2 -FrequencyRecurrenceFactor 1 -StartTime 020000 -Force
@@ -104,29 +100,19 @@ Describe "$commandname Integration Tests" -Tags "UnitTests" {
104100
}
105101

106102
$null = New-DbaAgentSchedule @ScheduleParams -Force
107-
108-
Write-Message -Level Warning -Message "BeforeAll end: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)"
109103
}
110104
AfterAll {
111-
Write-Message -Level Warning -Message "AfterAll start: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)"
112-
113105
$schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance2 -Schedule dbatoolsci_WeeklyTest, dbatoolsci_MonthlyTest, Issue_6636_Once, Issue_6636_Once_Copy, Issue_6636_Hour, Issue_6636_Hour_Copy, Issue_6636_Minute, Issue_6636_Minute_Copy, Issue_6636_Second, Issue_6636_Second_Copy, Issue_6636_OneTime, Issue_6636_OneTime_Copy, Issue_6636_AutoStart, Issue_6636_AutoStart_Copy, Issue_6636_OnIdle, Issue_6636_OnIdle_Copy
114106

115107
if ($null -ne $schedules) {
116108
$schedules.DROP()
117-
} else {
118-
Write-Message -Level Warning -Message "The schedules from $TestConfig.instance2 were returned as null"
119109
}
120110

121111
$schedules = Get-DbaAgentSchedule -SqlInstance $TestConfig.instance3 -Schedule dbatoolsci_MonthlyTest
122112

123113
if ($null -ne $schedules) {
124114
$schedules.DROP()
125-
} else {
126-
Write-Message -Level Warning -Message "The schedules from $TestConfig.instance3 were returned as null"
127115
}
128-
129-
Write-Message -Level Warning -Message "AfterAll end: Get-DbaAgentSchedule.Tests.ps1 testing with instance3=$($TestConfig.instance3) and instance2=$($TestConfig.instance2)"
130116
}
131117

132118
Context "Gets the list of Schedules" {

tests/Get-DbaDbSchema.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
1818
$random = Get-Random
1919
$server1 = Connect-DbaInstance -SqlInstance $TestConfig.instance1
2020
$server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2
21-
$null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false
21+
$null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue
2222
$newDbName = "dbatoolsci_newdb_$random"
2323
$newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName
2424

tests/Get-DbaDependency.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
133133

134134
It "Test with a tables that have circular dependencies" {
135135
# this causes infinite loop when circular dependencies exist in dependency tree.
136-
$results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency
136+
$results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -WarningAction SilentlyContinue
137+
# TODO: Test for "Circular Reference detected
137138
$results.length | Should -Be 2
138139
$results[0].Dependent | Should -Be "dbatoolsci_circrefB"
139140
$results[0].Tier | Should -Be 1
@@ -143,7 +144,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
143144

144145
It "Test with a tables that have circular dependencies and use -IncludeSelf" {
145146
# this causes infinite loop when circular dependencies exist in dependency tree.
146-
$results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -IncludeSelf
147+
$results = Get-DbaDbTable -SqlInstance $TestConfig.instance1 -Database $dbname -Table dbo.dbatoolsci_circrefA | Get-DbaDependency -IncludeSelf -WarningAction SilentlyContinue
148+
# TODO: Test for "Circular Reference detected
147149
$results.length | Should -Be 3
148150
$results[0].Dependent | Should -Be "dbatoolsci_circrefA"
149151
$results[0].Tier | Should -Be 0

tests/Get-DbaExtendedProperty.Tests.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
1717
BeforeAll {
1818
$random = Get-Random
1919
$server2 = Connect-DbaInstance -SqlInstance $TestConfig.instance2
20-
$null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false
2120
$newDbName = "dbatoolsci_newdb_$random"
2221
$db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName
2322
$db.Query("EXEC sys.sp_addextendedproperty @name=N'dbatoolz', @value=N'woo'")

tests/Get-DbaLastBackup.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
1919
$dbname = "dbatoolsci_getlastbackup$random"
2020
$server.Query("CREATE DATABASE $dbname")
2121
$server.Query("ALTER DATABASE $dbname SET RECOVERY FULL WITH NO_WAIT")
22-
$backupdir = Join-Path $server.BackupDirectory $dbname
22+
$backupdir = Join-Path $TestConfig.Temp $dbname
2323
if (-not (Test-Path $backupdir -PathType Container)) {
2424
$null = New-Item -Path $backupdir -ItemType Container
2525
}
@@ -62,7 +62,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
6262

6363
Context "Get last history for one split database" {
6464
It "supports multi-file backups" {
65-
$null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -FileCount 4
65+
$null = Backup-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $dbname -BackupDirectory $backupdir -FileCount 4
6666
$results = Get-DbaLastBackup -SqlInstance $TestConfig.instance2 -Database $dbname | Select-Object -First 1
6767
$results.LastFullBackup.GetType().Name | Should -Be "DbaDateTime"
6868
}

0 commit comments

Comments
 (0)