-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7a87f5
commit 12cf17d
Showing
3 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,58 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} | ||
param($ModuleName = 'dbatools') | ||
$global:TestConfig = Get-TestConfig | ||
|
||
Describe "$CommandName Unit Tests" -Tag 'UnitTests' { | ||
Describe "Add-DbaAgDatabase" { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} | ||
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Database', 'Secondary', 'SecondarySqlCredential', 'InputObject', 'SeedingMode', 'SharedPath', 'UseLastBackup', 'AdvancedBackupParams', '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 | ||
BeforeAll { | ||
$command = Get-Command Add-DbaAgDatabase | ||
} | ||
$parms = @( | ||
"SqlInstance", | ||
"SqlCredential", | ||
"AvailabilityGroup", | ||
"Database", | ||
"Secondary", | ||
"SecondarySqlCredential", | ||
"InputObject", | ||
"SeedingMode", | ||
"SharedPath", | ||
"UseLastBackup", | ||
"AdvancedBackupParams", | ||
"EnableException", | ||
"WhatIf", | ||
"Confirm" | ||
) | ||
It "Has required parameter: <_>" -ForEach $parms { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
} | ||
} | ||
|
||
Describe "$commandname Integration Tests" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$null = Get-DbaProcess -SqlInstance $TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue | ||
$server = Connect-DbaInstance -SqlInstance $TestConfig.instance3 | ||
$agname = "dbatoolsci_addagdb_agroup" | ||
$dbname = "dbatoolsci_addagdb_agroupdb" | ||
$newdbname = "dbatoolsci_addag_agroupdb_2" | ||
$server.Query("create database $dbname") | ||
$backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $dbname | Backup-DbaDatabase | ||
$ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert | ||
} | ||
AfterAll { | ||
$null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false | ||
$null = Remove-DbaDatabase -SqlInstance $server -Database $dbname, $newdbname -Confirm:$false | ||
} | ||
Context "adds ag db" { | ||
It "returns proper results" { | ||
Context "Integration Tests" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$null = Get-DbaProcess -SqlInstance $global:TestConfig.instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue | ||
$server = Connect-DbaInstance -SqlInstance $global:TestConfig.instance3 | ||
$agname = "dbatoolsci_addagdb_agroup" | ||
$dbname = "dbatoolsci_addagdb_agroupdb" | ||
$newdbname = "dbatoolsci_addag_agroupdb_2" | ||
$server.Query("create database $dbname") | ||
$backup = Get-DbaDatabase -SqlInstance $global:TestConfig.instance3 -Database $dbname | Backup-DbaDatabase | ||
$ag = New-DbaAvailabilityGroup -Primary $global:TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Database $dbname -Confirm:$false -Certificate dbatoolsci_AGCert | ||
} | ||
|
||
AfterAll { | ||
$null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false | ||
$null = Remove-DbaDatabase -SqlInstance $server -Database $dbname, $newdbname -Confirm:$false | ||
} | ||
|
||
It "adds ag db and returns proper results" { | ||
$server.Query("create database $newdbname") | ||
$backup = Get-DbaDatabase -SqlInstance $TestConfig.instance3 -Database $newdbname | Backup-DbaDatabase | ||
$results = Add-DbaAgDatabase -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false | ||
$backup = Get-DbaDatabase -SqlInstance $global:TestConfig.instance3 -Database $newdbname | Backup-DbaDatabase | ||
$results = Add-DbaAgDatabase -SqlInstance $global:TestConfig.instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false | ||
$results.AvailabilityGroup | Should -Be $agname | ||
$results.Name | Should -Be $newdbname | ||
$results.IsJoined | Should -Be $true | ||
} | ||
} | ||
} #$TestConfig.instance2 for appveyor | ||
} | ||
#$global:TestConfig.instance2 for appveyor |