Skip to content

Commit 072e653

Browse files
Fixes for a lot of tests that outputed unwanted warnings (#9764)
Co-authored-by: Chrissy LeMaire <[email protected]>
1 parent 2273d0f commit 072e653

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+187
-5507
lines changed

tests/Import-DbaCsv.Tests.ps1

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,135 +14,139 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
1414
}
1515

1616
Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
17-
AfterAll {
18-
# TODO: WARNING: [12:43:16][Invoke-DbaQuery] [CLIENT\SQLInstance2] Failed during execution | Cannot drop the table 'CommaSeparatedWithHeader', because it does not exist or you do not have permission.
19-
Invoke-DbaQuery -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader"
17+
BeforeAll {
18+
$pathSuperSmall = "$($TestConfig.appveyorlabrepo)\csv\SuperSmall.csv"
19+
$pathCommaSeparatedWithHeader = "$($TestConfig.appveyorlabrepo)\csv\CommaSeparatedWithHeader.csv"
20+
$pathCols = "$($TestConfig.appveyorlabrepo)\csv\cols.csv"
21+
$pathCol2 = "$($TestConfig.appveyorlabrepo)\csv\col2.csv"
22+
$pathPipe3 = "$($TestConfig.appveyorlabrepo)\csv\pipe3.psv"
2023
}
2124

22-
$path = "$($TestConfig.appveyorlabrepo)\csv\SuperSmall.csv"
23-
$CommaSeparatedWithHeader = "$($TestConfig.appveyorlabrepo)\csv\CommaSeparatedWithHeader.csv"
24-
$col1 = "$($TestConfig.appveyorlabrepo)\csv\cols.csv"
25-
$col2 = "$($TestConfig.appveyorlabrepo)\csv\col2.csv"
26-
$pipe3 = "$($TestConfig.appveyorlabrepo)\csv\pipe3.psv"
27-
25+
AfterAll {
26+
Get-DbaDbTable -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Table SuperSmall, CommaSeparatedWithHeader | Remove-DbaDbTable -Confirm:$false
27+
}
2828

2929
Context "Works as expected" {
30-
$results = $path | Import-DbaCsv -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn -WarningAction SilentlyContinue
31-
# TODO: Test for "Table or view SuperSmall does not exist and AutoCreateTable was not specified"
3230
It "accepts piped input and doesn't add rows if the table does not exist" {
33-
$results | Should -Be $null
31+
$results = $pathSuperSmall | Import-DbaCsv -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable WarnVar -WarningAction SilentlyContinue
32+
33+
$WarnVar | Should -BeLike "*Table or view SuperSmall does not exist and AutoCreateTable was not specified*"
34+
$results | Should -BeNullOrEmpty
3435
}
3536

3637
It "creates the right columnmap (#7630), handles pipe delimiters (#7806)" {
37-
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $col1 -Database tempdb -AutoCreateTable -Table cols
38-
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $col2 -Database tempdb -Table cols
39-
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable
38+
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pathCols -Database tempdb -AutoCreateTable -Table cols
39+
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pathCol2 -Database tempdb -Table cols
40+
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pathPipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable
41+
42+
4043
$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query "select * from cols"
44+
4145
$results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty
4246
$results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty
47+
48+
4349
$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query "select * from cols2"
50+
4451
$results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty
4552
$results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty
4653
}
4754

48-
if (-not $env:appveyor) {
49-
$results = Import-DbaCsv -Path $path, $path -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable
50-
51-
It "performs 4 imports" {
52-
($results).Count | Should -Be 4
53-
}
55+
It "performs 4 imports" {
56+
$results = Import-DbaCsv -Path $pathSuperSmall, $pathSuperSmall -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable
5457

58+
($results).Count | Should -Be 4
5559
foreach ($result in $results) {
56-
It "returns the good stuff" {
57-
$result.RowsCopied | Should -Be 999
58-
$result.Database | Should -Be tempdb
59-
$result.Table | Should -Be SuperSmall
60-
}
61-
}
62-
63-
$result = Import-DbaCsv -Path $path -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate
64-
It "doesn't break when truncate is passed" {
6560
$result.RowsCopied | Should -Be 999
6661
$result.Database | Should -Be tempdb
6762
$result.Table | Should -Be SuperSmall
6863
}
64+
}
6965

70-
$result = Import-DbaCsv -Path $path -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction
71-
It "works with NoTransaction" {
72-
$result.RowsCopied | Should -Be 999
73-
$result.Database | Should -Be tempdb
74-
$result.Table | Should -Be SuperSmall
75-
}
66+
It "doesn't break when truncate is passed" {
67+
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate
68+
69+
$result.RowsCopied | Should -Be 999
70+
$result.Database | Should -Be tempdb
71+
$result.Table | Should -Be SuperSmall
72+
}
73+
74+
It "works with NoTransaction" {
75+
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction
76+
77+
$result.RowsCopied | Should -Be 999
78+
$result.Database | Should -Be tempdb
79+
$result.Table | Should -Be SuperSmall
7680
}
7781

7882
It "Catches the scenario where the database param does not match the server object passed into the command" {
79-
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
80-
$result = Import-DbaCsv -Path $path -SqlInstance $server -Database InvalidDB -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable -WarningAction SilentlyContinue
81-
# TODO: test for Cannot open database "InvalidDB" requested by the login. The login failed.
83+
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database InvalidDB -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable -WarningVariable WarnVar -WarningAction SilentlyContinue
84+
85+
$WarnVar | Should -BeLike "*Cannot open database * requested by the login. The login failed.*"
8286
$result | Should -BeNullOrEmpty
8387

84-
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
85-
$result = Import-DbaCsv -Path $path -SqlInstance $server -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable
88+
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable
89+
8690
$result.RowsCopied | Should -Be 999
8791
$result.Database | Should -Be tempdb
8892
$result.Table | Should -Be SuperSmall
8993
}
9094

9195
It "Catches the scenario where the header is not properly parsed causing param errors" {
92-
# TODO: WARNING: [12:43:13][Invoke-DbaQuery] [CLIENT] Failed during execution | Cannot drop the table 'NoHeaderRow', because it does not exist or you do not have permission.
93-
# TODO: What line writes the warning? Is this correct?
94-
9596
# create the table using AutoCreate
96-
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
97-
$null = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -AutoCreateTable
98-
97+
$null = Import-DbaCsv -Path $pathCommaSeparatedWithHeader -SqlInstance $TestConfig.instance1 -Database tempdb -AutoCreateTable
9998
# reload table without AutoCreate parameter to recreate bug #6553
100-
$result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Truncate
99+
$result = Import-DbaCsv -Path $pathCommaSeparatedWithHeader -SqlInstance $TestConfig.instance1 -Database tempdb -Truncate
100+
101101
$result.RowsCopied | Should -Be 1
102102
$result.Database | Should -Be tempdb
103103
$result.Table | Should -Be CommaSeparatedWithHeader
104-
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow'
104+
105+
Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query 'DROP TABLE CommaSeparatedWithHeader'
105106
}
106107

107108
It "works with NoHeaderRow" {
108109
# See #7759
109110
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
110111
Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE NoHeaderRow (c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50))'
111-
$result = Import-DbaCsv -Path $col1 -NoHeaderRow -SqlInstance $server -Database tempdb -Table 'NoHeaderRow' -WarningVariable warnNoHeaderRow
112+
113+
$result = Import-DbaCsv -Path $pathCols -NoHeaderRow -SqlInstance $server -Database tempdb -Table 'NoHeaderRow'
112114
$data = Invoke-DbaQuery -SqlInstance $server -Query 'SELECT * FROM NoHeaderRow' -As PSObject
113-
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow'
114115

115-
$warnNoHeaderRow | Should -BeNullOrEmpty
116-
$result | Should -Not -BeNullOrEmpty
117116
$result.RowsCopied | Should -Be 3
118117
$data[0].c1 | Should -Be 'firstcol'
118+
119+
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow'
119120
}
120121

121122
It "works with tables which have non-varchar types (date)" {
122123
# See #9433
123124
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
124125
Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithTypes ([date] DATE, col1 VARCHAR(50), col2 VARCHAR(50))'
125-
$result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Table 'WithTypes'
126-
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithTypes'
126+
$result = Import-DbaCsv -Path $pathCommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Table 'WithTypes'
127127

128128
$result | Should -Not -BeNullOrEmpty
129129
$result.RowsCopied | Should -Be 1
130+
131+
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithTypes'
130132
}
131133

132134
It "works with tables which have non-varchar types (guid, bit)" {
133135
# See #9433
134-
$filePath = '.\foo.csv'
136+
$filePath = "$($TestConfig.Temp)\foo.csv"
135137
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
136138
Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithGuidsAndBits (one_guid UNIQUEIDENTIFIER, one_bit BIT)'
137139
$row = [pscustomobject]@{
138140
one_guid = (New-Guid).Guid
139141
one_bit = 1
140142
}
141143
$row | Export-Csv -Path $filePath -NoTypeInformation
144+
142145
$result = Import-DbaCsv -Path $filePath -SqlInstance $server -Database tempdb -Table 'WithGuidsAndBits'
143-
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithGuidsAndBits'
144146

145147
$result.RowsCopied | Should -Be 1
148+
149+
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithGuidsAndBits'
146150
Remove-Item $filePath
147151
}
148152
}

tests/Install-DbaMaintenanceSolution.Tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
2424
Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -Query "drop procedure CommandExecute; drop procedure DatabaseBackup; drop procedure DatabaseIntegrityCheck; drop procedure IndexOptimize;"
2525
}
2626
It "does not overwrite existing " {
27-
$results = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2 -Database tempdb -WarningVariable warn -WarningAction SilentlyContinue
28-
$warn -match "already exists" | Should Be $true
27+
$results = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2 -Database tempdb -WarningVariable WarnVar -WarningAction SilentlyContinue
28+
$WarnVar | Should -Match "already exists"
2929
}
3030

3131
It "Continues the installation on other servers " {
32-
$results2 = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb
32+
$results2 = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb -WarningAction SilentlyContinue
3333
$sproc = Get-DbaDbModule -SqlInstance $TestConfig.instance3 -Database tempdb | Where-Object { $_.Name -eq "CommandExecute" }
3434
$sproc | Should -Not -BeNullOrEmpty
3535
}

tests/Install-DbaMultiTool.Tests.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
1717
BeforeAll {
1818
$branch = "main"
1919
$database = "dbatoolsci_multitool_$(Get-Random)"
20-
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
21-
$server.Query("CREATE DATABASE $database")
20+
$null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $database
2221

2322
$resultsDownload = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Branch $branch -Force -Verbose:$false
2423
}
@@ -48,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
4847
$folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch"
4948
$sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1
5049
Add-Content $sqlScript.FullName (New-Guid).ToString()
51-
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false
50+
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false -WarningAction SilentlyContinue
5251
$result = $result | Where-Object Name -eq $sqlScript.BaseName
5352
$result.Status -eq "Error" | Should -Be $true
5453
}
@@ -93,7 +92,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
9392
$folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch"
9493
$sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1
9594
Add-Content $sqlScript.FullName (New-Guid).ToString()
96-
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database -Verbose:$false
95+
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database -Verbose:$false -WarningAction SilentlyContinue
9796
$result = $result | Where-Object Name -eq $sqlScript.BaseName
9897
$result.Status -eq "Error" | Should -Be $true
9998
}

0 commit comments

Comments
 (0)