Skip to content

Commit

Permalink
adding tests (#5491)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret authored and potatoqualitee committed May 8, 2019
1 parent 25250a5 commit 91fc23b
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions tests/Get-DbaDbTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,36 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance','SqlCredential','Database','ExcludeDatabase','IncludeSystemDBs','Table','EnableException'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'IncludeSystemDBs', 'Table', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0
}
}
}
<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/sqlcollaborative/dbatools/blob/development/contributing.md#tests
for more guidence.
#>

Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$dbname = "dbatoolsscidb_$(Get-Random)"
$null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbname -Owner sa
$tablename = "dbatoolssci_$(Get-Random)"
$null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "Create table $tablename (col1 int)"
}
AfterAll {
$null = Invoke-DbaQuery -SqlInstance $script:instance1 -Database $dbname -Query "drop table $tablename"
$null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -Confirm:$false
}
Context "Should get the table" {
It "Gets the table" {
(Get-DbaDbTable -SqlInstance $script:instance1).Name | Should Contain $tablename
}
It "Gets the table when you specify the database" {
(Get-DbaDbTable -SqlInstance $script:instance1 -Database $dbname).Name | Should Contain $tablename
}
}
Context "Should not get the table if database is excluded" {
It "Doesn't find the table" {
(Get-DbaDbTable -SqlInstance $script:instance1 -ExcludeDatabase $dbname).Name | Should Not Contain $tablename
}
}
}

0 comments on commit 91fc23b

Please sign in to comment.