Skip to content
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

Fix tests for Availability Groups #9500

Merged
merged 7 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions tests/Add-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
}
Context "creates a listener" {
It "returns results with proper data" {
$results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Confirm:$false
$results.PortNumber | Should -Be 1433
$results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false
$results.PortNumber | Should -Be 14330
}
}
} #$script:instance2 for appveyor
14 changes: 9 additions & 5 deletions tests/Add-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {
}
}
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$agname = "dbatoolsci_agroup"
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false
$replicaName = $ag.PrimaryReplica
}
AfterAll {
Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false
$null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
}
Context "gets ag replicas" {
# the only way to test, really, is to call New-DbaAvailabilityGroup which calls Add-DbaAgReplica
$agname = "dbatoolsci_add_replicagroup"
$null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert

$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false
$replicaName = $ag.PrimaryReplica

It "returns results with proper data" {
$results = Get-DbaAgReplica -SqlInstance $script:instance3
Expand All @@ -30,8 +35,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$results.FailoverMode | Should -Contain 'Manual'
}
It "returns just one result" {
$server = Connect-DbaInstance -SqlInstance $script:instance3
$results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $server.DomainInstanceName -AvailabilityGroup $agname
$results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname
$results.AvailabilityGroup | Should -Be $agname
$results.Role | Should -Be 'Primary'
$results.AvailabilityMode | Should -Be 'SynchronousCommit'
Expand Down
8 changes: 4 additions & 4 deletions tests/Get-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$agname = "dbatoolsci_ag_listener"
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert |
Add-DbaAgListener -IPAddress 127.0.20.1 -Confirm:$false
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false
$ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false
}
AfterAll {
$null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false
$null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
}
Context "gets ags" {
It "returns results with proper data" {
$results = Get-DbaAgListener -SqlInstance $script:instance3
$results.PortNumber | Should -Contain 1433
$results.PortNumber | Should -Contain 14330
}
}
} #$script:instance2 for appveyor
8 changes: 4 additions & 4 deletions tests/Get-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$agname = "dbatoolsci_agroup"
$null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false
$replicaName = $ag.PrimaryReplica
}
AfterAll {
Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false
$null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
}
Context "gets ag replicas" {
It "returns results with proper data" {
Expand All @@ -29,8 +30,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$results.AvailabilityMode | Should -Contain 'SynchronousCommit'
}
It "returns just one result" {
$server = Connect-DbaInstance -SqlInstance $script:instance3
$results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $server.DomainInstanceName -AvailabilityGroup $agname
$results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname
$results.AvailabilityGroup | Should -Be $agname
$results.Role | Should -Be 'Primary'
$results.AvailabilityMode | Should -Be 'SynchronousCommit'
Expand Down
18 changes: 5 additions & 13 deletions tests/New-DbaAvailabilityGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,16 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' {

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$computername = ($script:instance3).Split("\")[0]
$null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue
$server = Connect-DbaInstance -SqlInstance $script:instance3
$dbname = "dbatoolsci_addag_agroupdb"
$server.Query("create database $dbname")
$agname = "dbatoolsci_addag_agroup"
$password = 'MyV3ry$ecur3P@ssw0rd'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$null = New-DbaDbMasterKey -SqlInstance $script:instance3 -Database master -WarningAction SilentlyContinue -ErrorAction Ignore -EnableException:$false -SecurePassword $securePassword -Confirm:$false
$null = New-DbaDbCertificate -SqlInstance $script:instance3 -Database master -Name dbatoolsci_AGCert -Subject 'AG Certificate' -ErrorAction Ignore
$null = New-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring -Name dbatoolsci_AGEndpoint -Certificate dbatoolsci_AGCert | Start-DbaEndpoint
$backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase
$null = New-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase
}
AfterEach {
$result = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
}
AfterAll {
$null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false
$null = Remove-DbaEndpoint -SqlInstance $server -Endpoint dbatoolsci_AGEndpoint -Confirm:$false
$null = Get-DbaDbCertificate -SqlInstance $server -Certificate dbatoolsci_AGCert | Remove-DbaDbCertificate -Confirm:$false
$null = Remove-DbaDatabase -SqlInstance $server -Database $dbname -Confirm:$false
$null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -Confirm:$false
}
Context "adds an ag" {
It "returns an ag with a db named" {
Expand Down
2 changes: 1 addition & 1 deletion tests/Remove-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$agname = "dbatoolsci_ag_removelistener"
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert
$aglistener = $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Confirm:$false
$aglistener = $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false
}
AfterAll {
$null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
Expand Down
15 changes: 8 additions & 7 deletions tests/Set-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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', 'AvailabilityGroup', 'Replica', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'EndpointUrl', 'ReadonlyRoutingConnectionUrl', 'InputObject', 'EnableException', 'ReadOnlyRoutingList'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Replica', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'SessionTimeout', 'EndpointUrl', 'ReadonlyRoutingConnectionUrl', 'ReadOnlyRoutingList', 'InputObject', '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
Expand All @@ -16,24 +16,25 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$agname = "dbatoolsci_arepgroup"
$null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false
$replicaName = $ag.PrimaryReplica
}
AfterAll {
Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
}
Context "sets ag properties" {
It "returns modified results" {
$results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -BackupPriority 5000
$results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -BackupPriority 100 -Confirm:$false
$results.AvailabilityGroup | Should -Be $agname
$results.BackupPriority | Should -Be 5000
$results.BackupPriority | Should -Be 100
}
It "returns modified results" {
$results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -BackupPriority 1000
$results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -SeedingMode Automatic -Confirm:$false
$results.AvailabilityGroup | Should -Be $agname
$results.BackupPriority | Should -Be 1000
$results.SeedingMode | Should -Be Automatic
}
It "attempts to add a ReadOnlyRoutingList" {
$null = Get-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname | Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningVariable warn
$null = Get-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname | Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false
$warn | Should -match "does not exist. Only availability"
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/pester.groups.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ $TestsRunGroups = @{
'Invoke-DbaDbMirroring',
# previous tests that were failing on older versions too
'Remove-DbaAvailabilityGroup',
'Set-DbaAgReplica',
'Read-DbaAuditFile',
'Sync-DbaLoginPermission',
'Read-DbaXEFile',
Expand All @@ -60,7 +59,6 @@ $TestsRunGroups = @{
'Test-DbaManagementObject',
'Export-DbaDacPackage',
'New-DbaDbTransfer',
'Remove-DbaAgDatabase',
'Get-DbaDbSynonym',
'Get-DbaDbVirtualLogFile',
'Get-DbaFile',
Expand Down
Loading