Skip to content

Commit

Permalink
Pester v5
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 14, 2024
1 parent db51ac3 commit 7a151c9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 60 deletions.
52 changes: 26 additions & 26 deletions tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ $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" {
[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 Tests" {
# Unit Tests
Describe "Unit Tests" -Tag 'UnitTests' {
It "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
$params | Should -BeExactly $knownParameters
}
}
}

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" {
# Integration Tests
Describe "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
}
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
Expand All @@ -38,4 +38,4 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
$results.IsJoined | Should -Be $true
}
}
} #$script:instance2 for appveyor
} #$script:instance2 for appveyor
17 changes: 9 additions & 8 deletions tests/Add-DbaReplArticle.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ $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" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Publication', 'Schema', 'Name', 'Filter', 'CreationScriptOptions', '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 Tests" {
# Unit Tests
Describe "Unit Tests" -Tag 'UnitTests' {
It "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Publication', 'Schema', 'Name', 'Filter', 'CreationScriptOptions', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
$params | Should -BeExactly $knownParameters
}
}
}
<#
Integration tests for replication are in GitHub Actions and run from \tests\gh-actions-repl-*.ps1.ps1
#>
#>
51 changes: 25 additions & 26 deletions tests/Add-DbaServerRoleMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
. "$PSScriptRoot\constants.ps1"

Describe "$CommandName Unit Tests" -Tags "UnitTests" {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('WhatIf', 'Confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'ServerRole', 'Login', 'Role', '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 Tests" {
# Unit Tests
Describe "Unit Tests" -Tags "UnitTests" {
It "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('WhatIf', 'Confirm')}
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'ServerRole', 'Login', 'Role', 'InputObject', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
$params | Should -BeExactly $knownParameters
}
}
}

Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$login1 = "dbatoolsci_login1_$(Get-Random)"
$login2 = "dbatoolsci_login2_$(Get-Random)"
$customServerRole = "dbatoolsci_customrole_$(Get-Random)"
$fixedServerRoles = 'dbcreator','processadmin'
$null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaServerRole -SqlInstance $script:instance2 -ServerRole $customServerRole -Owner sa
}
AfterAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1, $login2 -Confirm:$false
}
# Integration Tests
Describe "Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$login1 = "dbatoolsci_login1_$(Get-Random)"
$login2 = "dbatoolsci_login2_$(Get-Random)"
$customServerRole = "dbatoolsci_customrole_$(Get-Random)"
$fixedServerRoles = 'dbcreator','processadmin'
$null = New-DbaLogin -SqlInstance $script:instance2 -Login $login1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaLogin -SqlInstance $script:instance2 -Login $login2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaServerRole -SqlInstance $script:instance2 -ServerRole $customServerRole -Owner sa
}
AfterAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $login1, $login2 -Confirm:$false
}

Context "Functionality" {
It 'Adds Login to Role' {
Add-DbaServerRoleMember -SqlInstance $script:instance2 -ServerRole $fixedServerRoles[0] -Login $login1 -Confirm:$false
$roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0]
Expand All @@ -45,7 +45,6 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
$roleDBAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles
$roleDBAfter.Count | Should -Be $serverRoles.Count
$roleDBAfter.Login -contains $login1 | Should -Be $true

}

It 'Adds Customer Server-Level Role Membership' {
Expand All @@ -64,4 +63,4 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
$roleAfter.EnumMemberNames().Contains($login2) | Should -Be $true
}
}
}
}

0 comments on commit 7a151c9

Please sign in to comment.