Skip to content

Commit

Permalink
start from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 16, 2024
1 parent 0c39b6a commit 915656a
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 434 deletions.
64 changes: 16 additions & 48 deletions tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,17 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
BeforeAll {
# Command under test
$CommandUnderTest = Get-Command $CommandName
}

Context "Validate parameters" {
It "Should have the correct parameters" {
$CommandUnderTest | Should -HaveParameter SqlInstance -Type DbaInstanceParameter
$CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential
$CommandUnderTest | Should -HaveParameter AvailabilityGroup -Type String
$CommandUnderTest | Should -HaveParameter Database -Type String[]
$CommandUnderTest | Should -HaveParameter Secondary -Type DbaInstanceParameter[]
$CommandUnderTest | Should -HaveParameter SecondarySqlCredential -Type PSCredential
$CommandUnderTest | Should -HaveParameter InputObject -Type Database[]
$CommandUnderTest | Should -HaveParameter SeedingMode -Type String
$CommandUnderTest | Should -HaveParameter SharedPath -Type String
$CommandUnderTest | Should -HaveParameter UseLastBackup -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter AdvancedBackupParams -Type Hashtable
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter
}

It "Should have the correct common parameters" {
$CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference
$CommandUnderTest | Should -HaveParameter WarningAction -Type ActionPreference
$CommandUnderTest | Should -HaveParameter InformationAction -Type ActionPreference
$CommandUnderTest | Should -HaveParameter ProgressAction -Type ActionPreference
$CommandUnderTest | Should -HaveParameter ErrorVariable -Type String
$CommandUnderTest | Should -HaveParameter WarningVariable -Type String
$CommandUnderTest | Should -HaveParameter InformationVariable -Type String
$CommandUnderTest | Should -HaveParameter OutVariable -Type String
$CommandUnderTest | Should -HaveParameter OutBuffer -Type Int32
$CommandUnderTest | Should -HaveParameter PipelineVariable -Type String
$CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter
[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
}
}
}

Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
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
Expand All @@ -54,20 +24,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$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
}

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
$results.AvailabilityGroup | Should -Be $agname
$results.Name | Should -Be $newdbname
$results.IsJoined | Should -Be $true
Context "adds ag db" {
It "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
$results.AvailabilityGroup | Should -Be $agname
$results.Name | Should -Be $newdbname
$results.IsJoined | Should -Be $true
}
}
}

#$script:instance2 for appveyor
} #$script:instance2 for appveyor
29 changes: 9 additions & 20 deletions tests/Add-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
BeforeAll {
$CommandUnderTest = Get-Command $CommandName
}
Context "Validate parameters" {
It "Should have the correct parameters" {
$CommandUnderTest | Should -HaveParameter SqlInstance -Type DbaInstanceParameter[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory
$CommandUnderTest | Should -HaveParameter AvailabilityGroup -Type String[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Name -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter IPAddress -Type IPAddress[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter SubnetIP -Type IPAddress[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter SubnetMask -Type IPAddress[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Port -Type Int32 -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Dhcp -Type SwitchParameter -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter -Not -Mandatory
$CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory
[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
}
}
}
Expand All @@ -30,16 +19,16 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$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" {
BeforeEach {
$null = Remove-DbaAgListener -SqlInstance $script:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false
}
It "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
}
}
} #$script:instance2 for appveyor
} #$script:instance2 for appveyor
48 changes: 11 additions & 37 deletions tests/Add-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,30 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
BeforeAll {
$CommandUnderTest = Get-Command $CommandName
}

Describe "$commandname Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
It "Should have the correct parameters" {
$CommandUnderTest | Should -HaveParameter SqlInstance -Type DbaInstanceParameter[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Name -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter ClusterType -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter AvailabilityMode -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter FailoverMode -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter BackupPriority -Type Int32 -Not -Mandatory
$CommandUnderTest | Should -HaveParameter ConnectionModeInPrimaryRole -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter ConnectionModeInSecondaryRole -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter SeedingMode -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Endpoint -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter EndpointUrl -Type String[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter -Not -Mandatory
$CommandUnderTest | Should -HaveParameter ReadOnlyRoutingList -Type String[] -Not -Mandatory
$CommandUnderTest | Should -HaveParameter ReadonlyRoutingConnectionUrl -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter Certificate -Type String -Not -Mandatory
$CommandUnderTest | Should -HaveParameter ConfigureXESession -Type SwitchParameter -Not -Mandatory
$CommandUnderTest | Should -HaveParameter SessionTimeout -Type Int32 -Not -Mandatory
$CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup -Not -Mandatory
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory
[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 "$CommandName Integration Tests" -Tag "IntegrationTests" {
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" {
BeforeAll {
# 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
}
# 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
Expand All @@ -59,7 +34,6 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$results.AvailabilityMode | Should -Contain 'SynchronousCommit'
$results.FailoverMode | Should -Contain 'Manual'
}

It "returns just one result" {
$results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname
$results.AvailabilityGroup | Should -Be $agname
Expand Down
62 changes: 16 additions & 46 deletions tests/Add-DbaComputerCertificate.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,60 +1,30 @@
param($ModuleName = 'dbatools')

Describe "Add-DbaComputerCertificate" {
BeforeAll {
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"
}
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
BeforeAll {
$CommandUnderTest = Get-Command Add-DbaComputerCertificate
}
It "Should have ComputerName as a parameter" {
$CommandUnderTest | Should -HaveParameter ComputerName -Type DbaInstanceParameter[]
}
It "Should have Credential as a parameter" {
$CommandUnderTest | Should -HaveParameter Credential -Type PSCredential
}
It "Should have SecurePassword as a parameter" {
$CommandUnderTest | Should -HaveParameter SecurePassword -Type SecureString
}
It "Should have Certificate as a parameter" {
$CommandUnderTest | Should -HaveParameter Certificate -Type X509Certificate2[]
}
It "Should have Path as a parameter" {
$CommandUnderTest | Should -HaveParameter Path -Type String
}
It "Should have Store as a parameter" {
$CommandUnderTest | Should -HaveParameter Store -Type String
}
It "Should have Folder as a parameter" {
$CommandUnderTest | Should -HaveParameter Folder -Type String
}
It "Should have Flag as a parameter" {
$CommandUnderTest | Should -HaveParameter Flag -Type String[]
}
It "Should have EnableException as a parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter
[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 "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "Certificate is added properly" {
BeforeAll {
$results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false
}
$results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -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"
}

AfterAll {
Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false
}
Remove-DbaComputerCertificate -Thumbprint 29C469578D6C6211076A09CEE5C5797EEA0C2713 -Confirm:$false
}
}
}
Loading

0 comments on commit 915656a

Please sign in to comment.