-
-
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
c4bcd7b
commit 43ce0a5
Showing
4 changed files
with
227 additions
and
70 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,46 +1,95 @@ | ||
$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' { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } | ||
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Name', 'ClusterType', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'Endpoint', 'EndpointUrl', 'Passthru', 'ReadOnlyRoutingList', 'ReadonlyRoutingConnectionUrl', 'Certificate', 'ConfigureXESession', 'SessionTimeout', '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 | ||
Describe "Add-DbaAgReplica" -Tag "UnitTests" { | ||
Context "Parameter validation" { | ||
BeforeAll { | ||
$command = Get-Command Add-DbaAgReplica | ||
$expectedParameters = $TestConfig.CommonParameters | ||
|
||
$expectedParameters += @( | ||
"SqlInstance", | ||
"SqlCredential", | ||
"Name", | ||
"ClusterType", | ||
"AvailabilityMode", | ||
"FailoverMode", | ||
"BackupPriority", | ||
"ConnectionModeInPrimaryRole", | ||
"ConnectionModeInSecondaryRole", | ||
"SeedingMode", | ||
"Endpoint", | ||
"EndpointUrl", | ||
"Passthru", | ||
"ReadOnlyRoutingList", | ||
"ReadonlyRoutingConnectionUrl", | ||
"Certificate", | ||
"ConfigureXESession", | ||
"SessionTimeout", | ||
"InputObject", | ||
"EnableException" | ||
) | ||
} | ||
|
||
It "Has parameter: <_>" -ForEach $expectedParameters { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
|
||
It "Should have exactly the number of expected parameters" { | ||
$actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } | ||
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
Describe "$commandname Integration Tests" -Tag "IntegrationTests" { | ||
|
||
Describe "Add-DbaAgReplica" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$agname = "dbatoolsci_agroup" | ||
$ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false | ||
$replicaName = $ag.PrimaryReplica | ||
$primaryAgName = "dbatoolsci_agroup" | ||
$splatPrimary = @{ | ||
Primary = $TestConfig.instance3 | ||
Name = $primaryAgName | ||
ClusterType = "None" | ||
FailoverMode = "Manual" | ||
Certificate = "dbatoolsci_AGCert" | ||
Confirm = $false | ||
} | ||
$primaryAg = New-DbaAvailabilityGroup @splatPrimary | ||
$replicaName = $primaryAg.PrimaryReplica | ||
} | ||
|
||
AfterAll { | ||
$null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $agname -Confirm:$false | ||
$null = Remove-DbaAvailabilityGroup -SqlInstance $TestConfig.instance3 -AvailabilityGroup $primaryAgName -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" | ||
$ag = New-DbaAvailabilityGroup -Primary $TestConfig.instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false | ||
$replicaName = $ag.PrimaryReplica | ||
|
||
It "returns results with proper data" { | ||
Context "When adding AG replicas" { | ||
BeforeAll { | ||
$replicaAgName = "dbatoolsci_add_replicagroup" | ||
$splatRepAg = @{ | ||
Primary = $TestConfig.instance3 | ||
Name = $replicaAgName | ||
ClusterType = "None" | ||
FailoverMode = "Manual" | ||
Certificate = "dbatoolsci_AGCert" | ||
Confirm = $false | ||
} | ||
$replicaAg = New-DbaAvailabilityGroup @splatRepAg | ||
} | ||
|
||
It "Returns results with proper data" { | ||
$results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 | ||
$results.AvailabilityGroup | Should -Contain $agname | ||
$results.AvailabilityGroup | Should -Contain $replicaAgName | ||
$results.Role | Should -Contain 'Primary' | ||
$results.AvailabilityMode | Should -Contain 'SynchronousCommit' | ||
$results.FailoverMode | Should -Contain 'Manual' | ||
} | ||
It "returns just one result" { | ||
$results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $agname | ||
$results.AvailabilityGroup | Should -Be $agname | ||
|
||
It "Returns just one result for a specific replica" { | ||
$results = Get-DbaAgReplica -SqlInstance $TestConfig.instance3 -Replica $replicaName -AvailabilityGroup $replicaAgName | ||
$results.AvailabilityGroup | Should -Be $replicaAgName | ||
$results.Role | Should -Be 'Primary' | ||
$results.AvailabilityMode | Should -Be 'SynchronousCommit' | ||
$results.FailoverMode | Should -Be 'Manual' | ||
} | ||
} | ||
} #$TestConfig.instance2 for appveyor | ||
|
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,30 +1,54 @@ | ||
$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' { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} | ||
[object[]]$knownParameters = 'ComputerName', 'Credential', 'SecurePassword', 'Certificate', 'Path', 'Store', 'Folder', 'Flag', '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 | ||
Describe "Add-DbaComputerCertificate" -Tag "UnitTests" { | ||
Context "Parameter validation" { | ||
BeforeAll { | ||
$command = Get-Command Add-DbaComputerCertificate | ||
$expectedParameters = $TestConfig.CommonParameters | ||
|
||
$expectedParameters += @( | ||
"ComputerName", | ||
"Credential", | ||
"SecurePassword", | ||
"Certificate", | ||
"Path", | ||
"Store", | ||
"Folder", | ||
"Flag", | ||
"EnableException" | ||
) | ||
} | ||
|
||
It "Has parameter: <_>" -ForEach $expectedParameters { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
|
||
It "Should have exactly the number of expected parameters" { | ||
$actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } | ||
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
|
||
Describe "$commandname Integration Tests" -Tags "IntegrationTests" { | ||
Describe "Add-DbaComputerCertificate" -Tag "IntegrationTests" { | ||
Context "Certificate is added properly" { | ||
$results = Add-DbaComputerCertificate -Path "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" -Confirm:$false | ||
BeforeAll { | ||
$certPath = "$($TestConfig.appveyorlabrepo)\certificates\localhost.crt" | ||
$results = Add-DbaComputerCertificate -Path $certPath -Confirm:$false | ||
} | ||
|
||
It "Should show the proper thumbprint has been added" { | ||
$results.Thumbprint | Should Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" | ||
$results.Thumbprint | Should -Be "29C469578D6C6211076A09CEE5C5797EEA0C2713" | ||
} | ||
|
||
It "Should be in LocalMachine\My Cert Store" { | ||
$results.PSParentPath | Should Be "Microsoft.PowerShell.Security\Certificate::LocalMachine\My" | ||
$results.PSParentPath | Should -Be "Microsoft.PowerShell.Security\Certificate::LocalMachine\My" | ||
} | ||
|
||
Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false | ||
AfterAll { | ||
Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false | ||
} | ||
} | ||
} |