Skip to content

Fixes for a lot of tests that outputed unwanted warnings #9764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Aug 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b91da92
Fix Import-DbaCsv (do Import-DbaCsv)
andreasjordan Aug 8, 2025
6d7d3d7
fix test (do Install-DbaMaintenanceSolution)
andreasjordan Aug 9, 2025
06738f5
fix test of Install-DbaMultiTool
andreasjordan Aug 9, 2025
f338d9c
fix test for Install-DbaWhoIsActive
andreasjordan Aug 9, 2025
e5501fd
fix test for Invoke-DbaDbCorruption
andreasjordan Aug 9, 2025
bd2b63a
fix test for Read-DbaXEFile
andreasjordan Aug 9, 2025
94a1c84
Fix test for Test-DbaMaxMemory
andreasjordan Aug 9, 2025
ae8cf02
fix test for Select-DbaDbSequenceNextValue
andreasjordan Aug 9, 2025
7c56d23
fix test for New-DbaAgentProxy
andreasjordan Aug 9, 2025
6445d74
fix test for New-DbaAgentSchedule
andreasjordan Aug 9, 2025
79adf9e
fix test for New-DbaCustomError
andreasjordan Aug 9, 2025
af2c054
fix test for New-DbaDatabase
andreasjordan Aug 9, 2025
da676b9
fix test for New-DbaDbFileGroup
andreasjordan Aug 9, 2025
e27a593
Fix test for New-DbaDbSchema
andreasjordan Aug 9, 2025
d9701dd
fix test for New-DbaDbSequence
andreasjordan Aug 9, 2025
e42e1e3
Fix for New-DbaDbUser
andreasjordan Aug 9, 2025
79892bc
Fix test for New-DbaLinkedServer
andreasjordan Aug 9, 2025
b96659f
Fix test for New-DbaLinkedServerLogin
andreasjordan Aug 9, 2025
1635774
Fix test for New-DbaRgResourcePool
andreasjordan Aug 9, 2025
b373f1a
Fix test for New-DbaRgWorkloadGroup
andreasjordan Aug 9, 2025
0e8a4fa
fix test
andreasjordan Aug 9, 2025
638031b
Fix test for Remove-DbaCustomError
andreasjordan Aug 9, 2025
64c2599
Fix test for Remove-DbaDbFileGroup
andreasjordan Aug 9, 2025
3b28494
Fix test for Remove-DbaDbOrphanUser
andreasjordan Aug 9, 2025
3a1222c
Fix test for Remove-DbaDbSchema
andreasjordan Aug 9, 2025
4438f13
Fix test for Remove-DbaDbTable
andreasjordan Aug 9, 2025
9bf5777
Fix test for Remove-DbaDbView
andreasjordan Aug 9, 2025
cd5c81b
Fix test for Remove-DbaExtendedProperty
andreasjordan Aug 9, 2025
f6ea246
Fix test for Remove-DbaLinkedServerLogin
andreasjordan Aug 9, 2025
79f2d26
Fix test for Remove-DbaRgResourcePool
andreasjordan Aug 9, 2025
fdfbb40
Fix test for Set-DbaAgentJobStep
andreasjordan Aug 9, 2025
dba19bb
Fix test for Set-DbaAgentOperator
andreasjordan Aug 9, 2025
f97611c
Fix test for Set-DbaAgentSchedule
andreasjordan Aug 9, 2025
3a42790
Fix test for Set-DbaDbFileGroup
andreasjordan Aug 9, 2025
032494b
Fix test for Set-DbaDbSchema
andreasjordan Aug 9, 2025
cf538e8
Fix test for Set-DbaDbSequence
andreasjordan Aug 9, 2025
d45126c
Fix test for Set-DbaExtendedProperty
andreasjordan Aug 9, 2025
80d96f0
Fix test for Set-DbaLogin
andreasjordan Aug 9, 2025
534d6bc
Fix test for Set-DbaResourceGovernor
andreasjordan Aug 9, 2025
df8d210
Fix test for Set-DbaRgResourcePool
andreasjordan Aug 9, 2025
6375c7a
Fix test for Set-DbaRgWorkloadGroup
andreasjordan Aug 9, 2025
dadd122
Fix test for Set-DbaTcpPort
andreasjordan Aug 9, 2025
45427ba
Fix test for Set-DbaTempDbConfig
andreasjordan Aug 9, 2025
eefd899
Enable test (do Set-DbaAgentJobStep)
andreasjordan Aug 9, 2025
8f7c31c
run all tests
andreasjordan Aug 9, 2025
c3808b1
don't use Express Edition (do Set-DbaAgentJobStep)
andreasjordan Aug 9, 2025
5850ff6
try to skip one It (do Set-DbaAgentJobStep)
andreasjordan Aug 9, 2025
30ee7f0
Still disable test for Set-DbaAgentJobStep on AppVeyor
andreasjordan Aug 9, 2025
b9a8e4d
Merge branch 'development' into fix_test_warnings
potatoqualitee Aug 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 61 additions & 57 deletions tests/Import-DbaCsv.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,135 +14,139 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
}

Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
AfterAll {
# 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.
Invoke-DbaQuery -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader"
BeforeAll {
$pathSuperSmall = "$($TestConfig.appveyorlabrepo)\csv\SuperSmall.csv"
$pathCommaSeparatedWithHeader = "$($TestConfig.appveyorlabrepo)\csv\CommaSeparatedWithHeader.csv"
$pathCols = "$($TestConfig.appveyorlabrepo)\csv\cols.csv"
$pathCol2 = "$($TestConfig.appveyorlabrepo)\csv\col2.csv"
$pathPipe3 = "$($TestConfig.appveyorlabrepo)\csv\pipe3.psv"
}

$path = "$($TestConfig.appveyorlabrepo)\csv\SuperSmall.csv"
$CommaSeparatedWithHeader = "$($TestConfig.appveyorlabrepo)\csv\CommaSeparatedWithHeader.csv"
$col1 = "$($TestConfig.appveyorlabrepo)\csv\cols.csv"
$col2 = "$($TestConfig.appveyorlabrepo)\csv\col2.csv"
$pipe3 = "$($TestConfig.appveyorlabrepo)\csv\pipe3.psv"

AfterAll {
Get-DbaDbTable -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Table SuperSmall, CommaSeparatedWithHeader | Remove-DbaDbTable -Confirm:$false
}

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

$WarnVar | Should -BeLike "*Table or view SuperSmall does not exist and AutoCreateTable was not specified*"
$results | Should -BeNullOrEmpty
}

It "creates the right columnmap (#7630), handles pipe delimiters (#7806)" {
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $col1 -Database tempdb -AutoCreateTable -Table cols
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $col2 -Database tempdb -Table cols
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pathCols -Database tempdb -AutoCreateTable -Table cols
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pathCol2 -Database tempdb -Table cols
$null = Import-DbaCsv -SqlInstance $TestConfig.instance1 -Path $pathPipe3 -Database tempdb -Table cols2 -Delimiter "|" -AutoCreateTable


$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query "select * from cols"

$results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty
$results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty


$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query "select * from cols2"

$results | Where-Object third -notmatch "three" | Should -BeNullOrEmpty
$results | Where-Object firstcol -notmatch "one" | Should -BeNullOrEmpty
}

if (-not $env:appveyor) {
$results = Import-DbaCsv -Path $path, $path -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable

It "performs 4 imports" {
($results).Count | Should -Be 4
}
It "performs 4 imports" {
$results = Import-DbaCsv -Path $pathSuperSmall, $pathSuperSmall -SqlInstance $TestConfig.instance1, $TestConfig.instance2 -Database tempdb -Delimiter `t -NotifyAfter 50000 -WarningVariable warn2 -AutoCreateTable

($results).Count | Should -Be 4
foreach ($result in $results) {
It "returns the good stuff" {
$result.RowsCopied | Should -Be 999
$result.Database | Should -Be tempdb
$result.Table | Should -Be SuperSmall
}
}

$result = Import-DbaCsv -Path $path -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate
It "doesn't break when truncate is passed" {
$result.RowsCopied | Should -Be 999
$result.Database | Should -Be tempdb
$result.Table | Should -Be SuperSmall
}
}

$result = Import-DbaCsv -Path $path -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction
It "works with NoTransaction" {
$result.RowsCopied | Should -Be 999
$result.Database | Should -Be tempdb
$result.Table | Should -Be SuperSmall
}
It "doesn't break when truncate is passed" {
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate

$result.RowsCopied | Should -Be 999
$result.Database | Should -Be tempdb
$result.Table | Should -Be SuperSmall
}

It "works with NoTransaction" {
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -NoTransaction

$result.RowsCopied | Should -Be 999
$result.Database | Should -Be tempdb
$result.Table | Should -Be SuperSmall
}

It "Catches the scenario where the database param does not match the server object passed into the command" {
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
$result = Import-DbaCsv -Path $path -SqlInstance $server -Database InvalidDB -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable -WarningAction SilentlyContinue
# TODO: test for Cannot open database "InvalidDB" requested by the login. The login failed.
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database InvalidDB -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable -WarningVariable WarnVar -WarningAction SilentlyContinue

$WarnVar | Should -BeLike "*Cannot open database * requested by the login. The login failed.*"
$result | Should -BeNullOrEmpty

$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
$result = Import-DbaCsv -Path $path -SqlInstance $server -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable
$result = Import-DbaCsv -Path $pathSuperSmall -SqlInstance $TestConfig.instance1 -Database tempdb -Delimiter `t -Table SuperSmall -Truncate -AutoCreateTable

$result.RowsCopied | Should -Be 999
$result.Database | Should -Be tempdb
$result.Table | Should -Be SuperSmall
}

It "Catches the scenario where the header is not properly parsed causing param errors" {
# 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.
# TODO: What line writes the warning? Is this correct?

# create the table using AutoCreate
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
$null = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -AutoCreateTable

$null = Import-DbaCsv -Path $pathCommaSeparatedWithHeader -SqlInstance $TestConfig.instance1 -Database tempdb -AutoCreateTable
# reload table without AutoCreate parameter to recreate bug #6553
$result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Truncate
$result = Import-DbaCsv -Path $pathCommaSeparatedWithHeader -SqlInstance $TestConfig.instance1 -Database tempdb -Truncate

$result.RowsCopied | Should -Be 1
$result.Database | Should -Be tempdb
$result.Table | Should -Be CommaSeparatedWithHeader
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow'

Invoke-DbaQuery -SqlInstance $TestConfig.instance1 -Database tempdb -Query 'DROP TABLE CommaSeparatedWithHeader'
}

It "works with NoHeaderRow" {
# See #7759
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE NoHeaderRow (c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50))'
$result = Import-DbaCsv -Path $col1 -NoHeaderRow -SqlInstance $server -Database tempdb -Table 'NoHeaderRow' -WarningVariable warnNoHeaderRow

$result = Import-DbaCsv -Path $pathCols -NoHeaderRow -SqlInstance $server -Database tempdb -Table 'NoHeaderRow'
$data = Invoke-DbaQuery -SqlInstance $server -Query 'SELECT * FROM NoHeaderRow' -As PSObject
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow'

$warnNoHeaderRow | Should -BeNullOrEmpty
$result | Should -Not -BeNullOrEmpty
$result.RowsCopied | Should -Be 3
$data[0].c1 | Should -Be 'firstcol'

Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow'
}

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

$result | Should -Not -BeNullOrEmpty
$result.RowsCopied | Should -Be 1

Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithTypes'
}

It "works with tables which have non-varchar types (guid, bit)" {
# See #9433
$filePath = '.\foo.csv'
$filePath = "$($TestConfig.Temp)\foo.csv"
$server = Connect-DbaInstance $TestConfig.instance1 -Database tempdb
Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithGuidsAndBits (one_guid UNIQUEIDENTIFIER, one_bit BIT)'
$row = [pscustomobject]@{
one_guid = (New-Guid).Guid
one_bit = 1
}
$row | Export-Csv -Path $filePath -NoTypeInformation

$result = Import-DbaCsv -Path $filePath -SqlInstance $server -Database tempdb -Table 'WithGuidsAndBits'
Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithGuidsAndBits'

$result.RowsCopied | Should -Be 1

Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithGuidsAndBits'
Remove-Item $filePath
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Install-DbaMaintenanceSolution.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -Query "drop procedure CommandExecute; drop procedure DatabaseBackup; drop procedure DatabaseIntegrityCheck; drop procedure IndexOptimize;"
}
It "does not overwrite existing " {
$results = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2 -Database tempdb -WarningVariable warn -WarningAction SilentlyContinue
$warn -match "already exists" | Should Be $true
$results = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2 -Database tempdb -WarningVariable WarnVar -WarningAction SilentlyContinue
$WarnVar | Should -Match "already exists"
}

It "Continues the installation on other servers " {
$results2 = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb
$results2 = Install-DbaMaintenanceSolution -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb -WarningAction SilentlyContinue
$sproc = Get-DbaDbModule -SqlInstance $TestConfig.instance3 -Database tempdb | Where-Object { $_.Name -eq "CommandExecute" }
$sproc | Should -Not -BeNullOrEmpty
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Install-DbaMultiTool.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$branch = "main"
$database = "dbatoolsci_multitool_$(Get-Random)"
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance2
$server.Query("CREATE DATABASE $database")
$null = New-DbaDatabase -SqlInstance $TestConfig.instance2 -Name $database

$resultsDownload = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Branch $branch -Force -Verbose:$false
}
Expand Down Expand Up @@ -48,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
$folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch"
$sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1
Add-Content $sqlScript.FullName (New-Guid).ToString()
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance2 -Database $database -Verbose:$false -WarningAction SilentlyContinue
$result = $result | Where-Object Name -eq $sqlScript.BaseName
$result.Status -eq "Error" | Should -Be $true
}
Expand Down Expand Up @@ -93,7 +92,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
$folder = Join-Path (Get-DbatoolsConfigValue -FullName Path.DbatoolsData) -Child "dba-multitool-$branch"
$sqlScript = Get-ChildItem $folder -Filter "sp_*.sql" | Select-Object -First 1
Add-Content $sqlScript.FullName (New-Guid).ToString()
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database -Verbose:$false
$result = Install-DbaMultiTool -SqlInstance $TestConfig.instance3 -Database $database -Verbose:$false -WarningAction SilentlyContinue
$result = $result | Where-Object Name -eq $sqlScript.BaseName
$result.Status -eq "Error" | Should -Be $true
}
Expand Down
Loading
Loading