Skip to content

Commit

Permalink
Pester script -> global
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 20, 2024
1 parent d615e36 commit 1edba47
Show file tree
Hide file tree
Showing 500 changed files with 3,692 additions and 3,692 deletions.
14 changes: 7 additions & 7 deletions tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {

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
$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 $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
$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
Expand All @@ -31,11 +31,11 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
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
$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
8 changes: 4 additions & 4 deletions tests/Add-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ 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
$ag = New-DbaAvailabilityGroup -Primary $global: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
$null = Remove-DbaAgListener -SqlInstance $global:instance3 -Listener $listenerName -AvailabilityGroup $agname -Confirm:$false
}
AfterAll {
$null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
$null = Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false
}
Context "creates a listener" {
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
} #$global:instance2 for appveyor
12 changes: 6 additions & 6 deletions tests/Add-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ 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
$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 $script:instance3 -AvailabilityGroup $agname -Confirm:$false
$null = Remove-DbaAvailabilityGroup -SqlInstance $global: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
$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 $script:instance3
$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 $script:instance3 -Replica $replicaName -AvailabilityGroup $agname
$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
2 changes: 1 addition & 1 deletion tests/Add-DbaComputerCertificate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {

Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
Context "Certificate is added properly" {
$results = Add-DbaComputerCertificate -Path $script:appveyorlabrepo\certificates\localhost.crt -Confirm:$false
$results = Add-DbaComputerCertificate -Path $global:appveyorlabrepo\certificates\localhost.crt -Confirm:$false

It "Should show the proper thumbprint has been added" {
$results.Thumbprint | Should Be "29C469578D6C6211076A09CEE5C5797EEA0C2713"
Expand Down
6 changes: 3 additions & 3 deletions tests/Add-DbaDbMirrorMonitor.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" {

Describe "$commandname Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue
$null = Remove-DbaDbMirrorMonitor -SqlInstance $global:instance2 -WarningAction SilentlyContinue
}
AfterAll {
$null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue
$null = Remove-DbaDbMirrorMonitor -SqlInstance $global:instance2 -WarningAction SilentlyContinue
}

It "adds the mirror monitor" {
$results = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue
$results = Add-DbaDbMirrorMonitor -SqlInstance $global:instance2 -WarningAction SilentlyContinue
$results.MonitorStatus | Should -Be 'Added'
}
}
30 changes: 15 additions & 15 deletions tests/Add-DbaDbRoleMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" {

Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
BeforeAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$server = Connect-DbaInstance -SqlInstance $global:instance2
$user1 = "dbatoolssci_user1_$(Get-Random)"
$user2 = "dbatoolssci_user2_$(Get-Random)"
$role = "dbatoolssci_role_$(Get-Random)"
$null = New-DbaLogin -SqlInstance $script:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaLogin -SqlInstance $script:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaLogin -SqlInstance $global:instance2 -Login $user1 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$null = New-DbaLogin -SqlInstance $global:instance2 -Login $user2 -Password ('Password1234!' | ConvertTo-SecureString -asPlainText -Force)
$dbname = "dbatoolsci_$(Get-Random)"
$null = New-DbaDatabase -SqlInstance $script:instance2 -Name $dbname -Owner sa
$null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user1 -Username $user1
$null = New-DbaDbUser -SqlInstance $script:instance2 -Database $dbname -Login $user2 -Username $user2
$null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user1 -Username $user1 -IncludeSystem
$null = New-DbaDbUser -SqlInstance $script:instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem
$null = New-DbaDatabase -SqlInstance $global:instance2 -Name $dbname -Owner sa
$null = New-DbaDbUser -SqlInstance $global:instance2 -Database $dbname -Login $user1 -Username $user1
$null = New-DbaDbUser -SqlInstance $global:instance2 -Database $dbname -Login $user2 -Username $user2
$null = New-DbaDbUser -SqlInstance $global:instance2 -Database msdb -Login $user1 -Username $user1 -IncludeSystem
$null = New-DbaDbUser -SqlInstance $global:instance2 -Database msdb -Login $user2 -Username $user2 -IncludeSystem
$null = $server.Query("CREATE ROLE $role", $dbname)
}
AfterAll {
$server = Connect-DbaInstance -SqlInstance $script:instance2
$server = Connect-DbaInstance -SqlInstance $global:instance2
$null = $server.Query("DROP USER $user1", 'msdb')
$null = $server.Query("DROP USER $user2", 'msdb')
$null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -confirm:$false
$null = Remove-DbaLogin -SqlInstance $script:instance2 -Login $user1, $user2 -confirm:$false
$null = Remove-DbaDatabase -SqlInstance $global:instance2 -Database $dbname -confirm:$false
$null = Remove-DbaLogin -SqlInstance $global:instance2 -Login $user1, $user2 -confirm:$false
}

Context "Functionality" {
It 'Adds User to Role' {
Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false
Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false
$roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role $role

$roleDBAfter.Role | Should Be $role
Expand All @@ -49,7 +49,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {

It 'Adds User to Multiple Roles' {
$roleDB = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole
Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -confirm:$false
Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role db_datareader, SQLAgentReaderRole -Member $user1 -Database msdb -confirm:$false

$roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database msdb -Role db_datareader, SQLAgentReaderRole
$roleDBAfter.Count | Should BeGreaterThan $roleDB.Count
Expand All @@ -69,14 +69,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
}

It 'Skip adding user to role if already a member' {
$messages = Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false -Verbose 4>&1
$messages = Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role $role -Member $user1 -Database $dbname -confirm:$false -Verbose 4>&1
$messageCount = ($messages -match 'Adding user').Count

$messageCount | Should Be 0
}

It 'Adds Role to Role' {
Add-DbaDbRoleMember -SqlInstance $script:instance2 -Role db_datawriter -Member $role -Database $dbname -confirm:$false
Add-DbaDbRoleMember -SqlInstance $global:instance2 -Role db_datawriter -Member $role -Database $dbname -confirm:$false
$roleDBAfter = Get-DbaDbRoleMember -SqlInstance $server -Database $dbname -Role db_datawriter

$roleDBAfter.MemberRole | Should Contain $role
Expand Down
2 changes: 1 addition & 1 deletion tests/Add-DbaExtendedProperty.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {

BeforeAll {
$random = Get-Random
$server2 = Connect-DbaInstance -SqlInstance $script:instance2
$server2 = Connect-DbaInstance -SqlInstance $global:instance2
$null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false
$newDbName = "dbatoolsci_newdb_$random"
$db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName
Expand Down
10 changes: 5 additions & 5 deletions tests/Add-DbaRegServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$group = "dbatoolsci-group1"
$regSrvName = "dbatoolsci-server12"
$regSrvDesc = "dbatoolsci-server123"
$groupobject = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group
$groupobject = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name $group
}
AfterAll {
Get-DbaRegServer -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false
Get-DbaRegServerGroup -SqlInstance $script:instance1, $script:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false
Get-DbaRegServer -SqlInstance $global:instance1, $global:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServer -Confirm:$false
Get-DbaRegServerGroup -SqlInstance $global:instance1, $global:instance2 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false
}

It "adds a registered server" {
$results1 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $srvName
$results1 = Add-DbaRegServer -SqlInstance $global:instance1 -ServerName $srvName
$results1.Name | Should -Be $srvName
$results1.ServerName | Should -Be $srvName
$results1.SqlInstance | Should -Not -Be $null
}
It "adds a registered server with extended properties" {
$results2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc
$results2 = Add-DbaRegServer -SqlInstance $global:instance1 -ServerName $RegsrvName -Name $srvName -Group $groupobject -Description $regSrvDesc
$results2.ServerName | Should -Be $regSrvName
$results2.Description | Should -Be $regSrvDesc
$results2.Name | Should -Be $srvName
Expand Down
12 changes: 6 additions & 6 deletions tests/Add-DbaRegServerGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$descriptionUpdated = "group description updated"
}
AfterAll {
Get-DbaRegServerGroup -SqlInstance $script:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false
Get-DbaRegServerGroup -SqlInstance $global:instance1 | Where-Object Name -match dbatoolsci | Remove-DbaRegServerGroup -Confirm:$false
}

It "adds a registered server group" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group
$results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name $group
$results.Name | Should -Be $group
$results.SqlInstance | Should -Not -Be $null
}
It "adds a registered server group with extended properties" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name $group2 -Description $description
$results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name $group2 -Description $description
$results.Name | Should -Be $group2
$results.Description | Should -Be $description
$results.SqlInstance | Should -Not -Be $null
}
It "supports hella pipe" {
$results = Get-DbaRegServerGroup -SqlInstance $script:instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous
$results = Get-DbaRegServerGroup -SqlInstance $global:instance1 -Id 1 | Add-DbaRegServerGroup -Name dbatoolsci-first | Add-DbaRegServerGroup -Name dbatoolsci-second | Add-DbaRegServerGroup -Name dbatoolsci-third | Add-DbaRegServer -ServerName dbatoolsci-test -Description ridiculous
$results.Group | Should -Be 'dbatoolsci-first\dbatoolsci-second\dbatoolsci-third'
}
It "adds a registered server group and sub-group when not exists" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $description
$results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name "$group\$group2" -Description $description
$results.Name | Should -Be $group2
$results.SqlInstance | Should -Not -Be $null
}
It "updates description of sub-group when it already exists" {
$results = Add-DbaRegServerGroup -SqlInstance $script:instance1 -Name "$group\$group2" -Description $descriptionUpdated
$results = Add-DbaRegServerGroup -SqlInstance $global:instance1 -Name "$group\$group2" -Description $descriptionUpdated
$results.Name | Should -Be $group2
$results.Description | Should -Be $descriptionUpdated
$results.SqlInstance | Should -Not -Be $null
Expand Down
Loading

0 comments on commit 1edba47

Please sign in to comment.