Skip to content

Commit

Permalink
new batch before sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 16, 2024
1 parent 3c80231 commit a7a61a3
Show file tree
Hide file tree
Showing 50 changed files with 2,907 additions and 1,606 deletions.
110 changes: 90 additions & 20 deletions tests/Copy-DbaDbTableData.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
param($ModuleName = 'dbatools')

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
It "Should only contain our specific parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
[object[]]$knownParameters = 'AutoCreateTable', 'BatchSize', 'BulkCopyTimeout', 'CheckConstraints', 'CommandTimeout', 'Database', 'Destination', 'DestinationDatabase', 'DestinationSqlCredential', 'DestinationTable', 'EnableException', 'FireTriggers', 'InputObject', 'KeepIdentity', 'KeepNulls', 'NoTableLock', 'NotifyAfter', 'Query', 'SqlCredential', 'SqlInstance', 'Table', 'Truncate', 'View', 'UseDefaultFileGroup'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters

(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should -Be 0
}
}
}
Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Describe "Copy-DbaDbTableData" {
BeforeAll {
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

$db = Get-DbaDatabase -SqlInstance $script:instance1 -Database tempdb
$db2 = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb
$null = $db.Query("CREATE TABLE dbo.dbatoolsci_example (id int);
Expand Down Expand Up @@ -49,6 +40,85 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$null = 1
}
}

Context "Validate parameters" {
BeforeAll {
$CommandUnderTest = Get-Command Copy-DbaDbTableData
}
It "Should have SqlInstance as a parameter" {
$CommandUnderTest | Should -HaveParameter SqlInstance -Type DbaInstanceParameter
}
It "Should have SqlCredential as a parameter" {
$CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential
}
It "Should have Destination as a parameter" {
$CommandUnderTest | Should -HaveParameter Destination -Type DbaInstanceParameter[]
}
It "Should have DestinationSqlCredential as a parameter" {
$CommandUnderTest | Should -HaveParameter DestinationSqlCredential -Type PSCredential
}
It "Should have Database as a parameter" {
$CommandUnderTest | Should -HaveParameter Database -Type String
}
It "Should have DestinationDatabase as a parameter" {
$CommandUnderTest | Should -HaveParameter DestinationDatabase -Type String
}
It "Should have Table as a parameter" {
$CommandUnderTest | Should -HaveParameter Table -Type String[]
}
It "Should have View as a parameter" {
$CommandUnderTest | Should -HaveParameter View -Type String[]
}
It "Should have Query as a parameter" {
$CommandUnderTest | Should -HaveParameter Query -Type String
}
It "Should have AutoCreateTable as a switch parameter" {
$CommandUnderTest | Should -HaveParameter AutoCreateTable -Type Switch
}
It "Should have BatchSize as a parameter" {
$CommandUnderTest | Should -HaveParameter BatchSize -Type Int32
}
It "Should have NotifyAfter as a parameter" {
$CommandUnderTest | Should -HaveParameter NotifyAfter -Type Int32
}
It "Should have DestinationTable as a parameter" {
$CommandUnderTest | Should -HaveParameter DestinationTable -Type String
}
It "Should have NoTableLock as a switch parameter" {
$CommandUnderTest | Should -HaveParameter NoTableLock -Type Switch
}
It "Should have CheckConstraints as a switch parameter" {
$CommandUnderTest | Should -HaveParameter CheckConstraints -Type Switch
}
It "Should have FireTriggers as a switch parameter" {
$CommandUnderTest | Should -HaveParameter FireTriggers -Type Switch
}
It "Should have KeepIdentity as a switch parameter" {
$CommandUnderTest | Should -HaveParameter KeepIdentity -Type Switch
}
It "Should have KeepNulls as a switch parameter" {
$CommandUnderTest | Should -HaveParameter KeepNulls -Type Switch
}
It "Should have Truncate as a switch parameter" {
$CommandUnderTest | Should -HaveParameter Truncate -Type Switch
}
It "Should have BulkCopyTimeout as a parameter" {
$CommandUnderTest | Should -HaveParameter BulkCopyTimeout -Type Int32
}
It "Should have CommandTimeout as a parameter" {
$CommandUnderTest | Should -HaveParameter CommandTimeout -Type Int32
}
It "Should have UseDefaultFileGroup as a switch parameter" {
$CommandUnderTest | Should -HaveParameter UseDefaultFileGroup -Type Switch
}
It "Should have InputObject as a parameter" {
$CommandUnderTest | Should -HaveParameter InputObject -Type TableViewBase[]
}
It "Should have EnableException as a switch parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch
}
}

Context "Data movement" {
It "copies the table data" {
$results = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_example2
Expand Down Expand Up @@ -76,6 +146,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
$result.RowsCopied | Should -Be 1
}
}

Context "Functionality checks" {
It "supports piping" {
$null = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example | Copy-DbaDbTableData -DestinationTable dbatoolsci_example2 -Truncate
Expand All @@ -91,7 +162,6 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
}

It "opens and closes connections properly" {
#regression test, see #3468
$results = Get-DbaDbTable -SqlInstance $script:instance1 -Database tempdb -Table 'dbo.dbatoolsci_example', 'dbo.dbatoolsci_example4' | Copy-DbaDbTableData -Destination $script:instance2 -DestinationDatabase tempdb -KeepIdentity -KeepNulls -BatchSize 5000 -Truncate
$results.Count | Should -Be 2
$table1DbCount = $db.Query("select id from dbo.dbatoolsci_example")
Expand All @@ -108,12 +178,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {

It "Should return nothing if Source and Destination are same" {
$result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -Truncate
$result | Should -Be $null
$result | Should -BeNullOrEmpty
}

It "Should warn if the destinaton table doesn't exist" {
$result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$result | Should -BeNullOrEmpty
$tablewarning | Should -Match Auto
}

Expand All @@ -124,8 +194,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {

It "Should warn if the source database doesn't exist" {
$result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null
$result | Should -Be $null
$result | Should -BeNullOrEmpty
$tablewarning | Should -Match "cannot open database"
}
}
}
}
Loading

0 comments on commit a7a61a3

Please sign in to comment.