-
-
Notifications
You must be signed in to change notification settings - Fork 817
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
b528ce4
commit 30f3a74
Showing
73 changed files
with
2,954 additions
and
2,141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,61 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
. "$PSScriptRoot\constants.ps1" | ||
param($ModuleName = 'dbatools') | ||
|
||
Describe "Add-DbaAgDatabase" { | ||
BeforeDiscovery { | ||
. "$PSScriptRoot\constants.ps1" | ||
} | ||
|
||
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', '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 | ||
} | ||
$paramList = @( | ||
'SqlInstance', | ||
'SqlCredential', | ||
'AvailabilityGroup', | ||
'Database', | ||
'Secondary', | ||
'SecondarySqlCredential', | ||
'InputObject', | ||
'SeedingMode', | ||
'SharedPath', | ||
'UseLastBackup', | ||
'AdvancedBackupParams', | ||
'EnableException', | ||
'WhatIf', | ||
'Confirm' | ||
) | ||
It "Should have parameter: <_>" -ForEach $paramList { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
} | ||
} | ||
|
||
Describe "$commandname Integration Tests" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue | ||
$server = Connect-DbaInstance -SqlInstance $script:instance3 | ||
$agname = "dbatoolsci_addagdb_agroup" | ||
$dbname = "dbatoolsci_addagdb_agroupdb" | ||
$newdbname = "dbatoolsci_addag_agroupdb_2" | ||
$server.Query("create database $dbname") | ||
$backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase | ||
$ag = New-DbaAvailabilityGroup -Primary $script: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:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue | ||
$server = Connect-DbaInstance -SqlInstance $global:instance3 | ||
$agname = "dbatoolsci_addagdb_agroup" | ||
$dbname = "dbatoolsci_addagdb_agroupdb" | ||
$newdbname = "dbatoolsci_addag_agroupdb_2" | ||
$server.Query("create database $dbname") | ||
$backup = Get-DbaDatabase -SqlInstance $global:instance3 -Database $dbname | Backup-DbaDatabase | ||
$ag = New-DbaAvailabilityGroup -Primary $global: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 $script:instance3 -Database $newdbname | Backup-DbaDatabase | ||
$results = Add-DbaAgDatabase -SqlInstance $script:instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false | ||
$backup = Get-DbaDatabase -SqlInstance $global:instance3 -Database $newdbname | Backup-DbaDatabase | ||
$results = Add-DbaAgDatabase -SqlInstance $global:instance3 -AvailabilityGroup $agname -Database $newdbname -Confirm:$false | ||
$results.AvailabilityGroup | Should -Be $agname | ||
$results.Name | Should -Be $newdbname | ||
$results.IsJoined | Should -Be $true | ||
} | ||
} | ||
} #$script:instance2 for appveyor | ||
} | ||
|
||
#$global: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,34 +1,51 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
. "$PSScriptRoot\constants.ps1" | ||
param($ModuleName = 'dbatools') | ||
|
||
Describe "Add-DbaAgListener" { | ||
BeforeDiscovery { | ||
. "$PSScriptRoot\constants.ps1" | ||
} | ||
|
||
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', 'Name', 'IPAddress', 'SubnetIP', 'SubnetMask', 'Port', 'Dhcp', 'Passthru', '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 | ||
BeforeAll { | ||
$command = Get-Command Add-DbaAgListener | ||
} | ||
$paramList = @( | ||
'SqlInstance', | ||
'SqlCredential', | ||
'AvailabilityGroup', | ||
'Name', | ||
'IPAddress', | ||
'SubnetIP', | ||
'SubnetMask', | ||
'Port', | ||
'Dhcp', | ||
'Passthru', | ||
'InputObject', | ||
'EnableException', | ||
'WhatIf', | ||
'Confirm' | ||
) | ||
It "Should have parameter: <_>" -ForEach $paramList { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
} | ||
} | ||
|
||
Describe "$commandname Integration Tests" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$agname = "dbatoolsci_ag_newlistener" | ||
$listenerName = 'dbatoolsci_listener' | ||
$ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert | ||
} | ||
AfterEach { | ||
$null = Remove-DbaAgListener -SqlInstance $script:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false | ||
} | ||
AfterAll { | ||
$null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false | ||
} | ||
Context "creates a listener" { | ||
It "returns results with proper data" { | ||
Context "Integration Tests" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$agname = "dbatoolsci_ag_newlistener" | ||
$listenerName = 'dbatoolsci_listener' | ||
$ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert | ||
} | ||
AfterAll { | ||
Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false | ||
} | ||
|
||
It "creates a listener and returns results with proper data" { | ||
$results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false | ||
$results.PortNumber | Should -Be 14330 | ||
|
||
# Cleanup | ||
Remove-DbaAgListener -SqlInstance $global:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false | ||
} | ||
} | ||
} #$script:instance2 for appveyor | ||
} #$global: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,45 +1,74 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
. "$PSScriptRoot\constants.ps1" | ||
param($ModuleName = 'dbatools') | ||
|
||
Describe "Add-DbaAgReplica" { | ||
BeforeDiscovery { | ||
. "$PSScriptRoot\constants.ps1" | ||
} | ||
|
||
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 | ||
BeforeAll { | ||
$command = Get-Command Add-DbaAgReplica | ||
} | ||
$knownParameters = @( | ||
'SqlInstance', | ||
'SqlCredential', | ||
'Name', | ||
'ClusterType', | ||
'AvailabilityMode', | ||
'FailoverMode', | ||
'BackupPriority', | ||
'ConnectionModeInPrimaryRole', | ||
'ConnectionModeInSecondaryRole', | ||
'SeedingMode', | ||
'Endpoint', | ||
'EndpointUrl', | ||
'Passthru', | ||
'ReadOnlyRoutingList', | ||
'ReadonlyRoutingConnectionUrl', | ||
'Certificate', | ||
'ConfigureXESession', | ||
'SessionTimeout', | ||
'InputObject', | ||
'EnableException', | ||
'WhatIf', | ||
'Confirm' | ||
) | ||
It "Should have the correct parameters" -ForEach $knownParameters { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
} | ||
} | ||
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 { | ||
$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" | ||
$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 | ||
$results.AvailabilityGroup | Should -Contain $agname | ||
$results.Role | Should -Contain 'Primary' | ||
$results.AvailabilityMode | Should -Contain 'SynchronousCommit' | ||
$results.FailoverMode | Should -Contain 'Manual' | ||
Context "Integration Tests" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$agname = "dbatoolsci_agroup" | ||
$ag = New-DbaAvailabilityGroup -Primary $global:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false | ||
$replicaName = $ag.PrimaryReplica | ||
} | ||
AfterAll { | ||
$null = Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false | ||
} | ||
It "returns just one result" { | ||
$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' | ||
$results.FailoverMode | Should -Be 'Manual' | ||
Context "gets ag replicas" { | ||
BeforeAll { | ||
$agname = "dbatoolsci_add_replicagroup" | ||
$ag = New-DbaAvailabilityGroup -Primary $global: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 $global:instance3 | ||
$results.AvailabilityGroup | Should -Contain $agname | ||
$results.Role | Should -Contain 'Primary' | ||
$results.AvailabilityMode | Should -Contain 'SynchronousCommit' | ||
$results.FailoverMode | Should -Contain 'Manual' | ||
} | ||
It "returns just one result" { | ||
$results = Get-DbaAgReplica -SqlInstance $global:instance3 -Replica $replicaName -AvailabilityGroup $agname | ||
$results.AvailabilityGroup | Should -Be $agname | ||
$results.Role | Should -Be 'Primary' | ||
$results.AvailabilityMode | Should -Be 'SynchronousCommit' | ||
$results.FailoverMode | Should -Be 'Manual' | ||
} | ||
} | ||
} | ||
} #$script:instance2 for appveyor | ||
} | ||
#$global: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,47 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan | ||
. "$PSScriptRoot\constants.ps1" | ||
param($ModuleName = 'dbatools') | ||
|
||
Describe "Add-DbaComputerCertificate" { | ||
BeforeDiscovery { | ||
. "$PSScriptRoot\constants.ps1" | ||
} | ||
|
||
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 | ||
BeforeAll { | ||
$command = Get-Command Add-DbaComputerCertificate | ||
} | ||
$paramsList = @( | ||
'ComputerName', | ||
'Credential', | ||
'SecurePassword', | ||
'Certificate', | ||
'Path', | ||
'Store', | ||
'Folder', | ||
'Flag', | ||
'EnableException', | ||
'WhatIf', | ||
'Confirm' | ||
) | ||
It "Should have parameter: <_>" -ForEach $paramsList { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
} | ||
} | ||
|
||
Describe "$commandname Integration Tests" -Tags "IntegrationTests" { | ||
Context "Certificate is added properly" { | ||
$results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false | ||
BeforeAll { | ||
$results = Add-DbaComputerCertificate -Path $global:appveyorlabrepo\certificates\localhost.crt -Confirm:$false | ||
} | ||
|
||
AfterAll { | ||
Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -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 | ||
} | ||
} | ||
} |
Oops, something went wrong.