Skip to content

Commit

Permalink
global var required by new scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 17, 2024
1 parent 50a0077 commit fca3e16
Show file tree
Hide file tree
Showing 632 changed files with 4,823 additions and 4,808 deletions.
14 changes: 7 additions & 7 deletions tests/Add-DbaAgDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ Describe "Add-DbaAgDatabase" {

Context "Command usage" {
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 {
Expand All @@ -68,11 +68,11 @@ Describe "Add-DbaAgDatabase" {

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
8 changes: 4 additions & 4 deletions tests/Add-DbaAgListener.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ Describe "Add-DbaAgListener" {
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
}
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
}
}
} #$script:instance2 for appveyor
} #$global:instance2 for appveyor
18 changes: 9 additions & 9 deletions tests/Add-DbaAgReplica.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Describe "Add-DbaAgReplica" {
$CommandUnderTest | Should -HaveParameter EndpointUrl -Type String[]
}
It "Should have Passthru parameter" {
$CommandUnderTest | Should -HaveParameter Passthru -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter Passthru -Type Switch
}
It "Should have ReadOnlyRoutingList parameter" {
$CommandUnderTest | Should -HaveParameter ReadOnlyRoutingList -Type String[]
Expand All @@ -59,7 +59,7 @@ Describe "Add-DbaAgReplica" {
$CommandUnderTest | Should -HaveParameter Certificate -Type String
}
It "Should have ConfigureXESession parameter" {
$CommandUnderTest | Should -HaveParameter ConfigureXESession -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter ConfigureXESession -Type Switch
}
It "Should have SessionTimeout parameter" {
$CommandUnderTest | Should -HaveParameter SessionTimeout -Type Int32
Expand All @@ -68,32 +68,32 @@ Describe "Add-DbaAgReplica" {
$CommandUnderTest | Should -HaveParameter InputObject -Type AvailabilityGroup
}
It "Should have EnableException parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch
}
}

Context "Command usage" {
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 {
Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false
Remove-DbaAvailabilityGroup -SqlInstance $global:instance3 -AvailabilityGroup $agname -Confirm:$false
}
It "gets ag replicas" {
$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

$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'
Expand All @@ -102,4 +102,4 @@ Describe "Add-DbaAgReplica" {
}
}

#$script:instance2 for appveyor
#$global:instance2 for appveyor
4 changes: 2 additions & 2 deletions tests/Add-DbaComputerCertificate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Describe "Add-DbaComputerCertificate" {
$CommandUnderTest | Should -HaveParameter Flag -Type String[]
}
It "Should have EnableException as a parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch
}
}

Context "Certificate is added properly" {
BeforeAll {
$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" {
Expand Down
16 changes: 8 additions & 8 deletions tests/Add-DbaDbMirrorMonitor.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Describe "Add-DbaDbMirrorMonitor" {
$CommandUnderTest | Should -HaveParameter SqlCredential -Type PSCredential
}
It "Should have EnableException as a parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch
}
It "Should have Verbose as a parameter" {
$CommandUnderTest | Should -HaveParameter Verbose -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter Verbose -Type Switch
}
It "Should have Debug as a parameter" {
$CommandUnderTest | Should -HaveParameter Debug -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter Debug -Type Switch
}
It "Should have ErrorAction as a parameter" {
$CommandUnderTest | Should -HaveParameter ErrorAction -Type ActionPreference
Expand Down Expand Up @@ -57,23 +57,23 @@ Describe "Add-DbaDbMirrorMonitor" {
$CommandUnderTest | Should -HaveParameter PipelineVariable -Type String
}
It "Should have WhatIf as a parameter" {
$CommandUnderTest | Should -HaveParameter WhatIf -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter WhatIf -Type Switch
}
It "Should have Confirm as a parameter" {
$CommandUnderTest | Should -HaveParameter Confirm -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter Confirm -Type Switch
}
}

Context "Command usage" {
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'
}
}
Expand Down
30 changes: 15 additions & 15 deletions tests/Add-DbaDbRoleMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,36 @@ Describe "Add-DbaDbRoleMember" {
$CommandUnderTest | Should -HaveParameter InputObject -Type Object[]
}
It "Should have EnableException as a parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch
}
}

Context "Integration Tests" {
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 {
$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
}

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 @@ -63,7 +63,7 @@ Describe "Add-DbaDbRoleMember" {

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 @@ -82,14 +82,14 @@ Describe "Add-DbaDbRoleMember" {
}

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
4 changes: 2 additions & 2 deletions tests/Add-DbaExtendedProperty.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Describe "Add-DbaExtendedProperty" {
$CommandUnderTest | Should -HaveParameter InputObject -Type PSObject[] -Not -Mandatory
}
It "Should have EnableException as a parameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory
}
}

Context "Integration Tests" {
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
4 changes: 2 additions & 2 deletions tests/Add-DbaPfDataCollectorCounter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Describe "Add-DbaPfDataCollectorCounter" {
It "Should have InputObject as a non-mandatory Object[] parameter" {
$CommandUnderTest | Should -HaveParameter InputObject -Type Object[] -Not -Mandatory
}
It "Should have EnableException as a non-mandatory SwitchParameter" {
$CommandUnderTest | Should -HaveParameter EnableException -Type SwitchParameter -Not -Mandatory
It "Should have EnableException as a non-mandatory Switch" {
$CommandUnderTest | Should -HaveParameter EnableException -Type Switch -Not -Mandatory
}
}
}
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 @@ -57,23 +57,23 @@ Describe "Add-DbaRegServer" {
$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 -BeNullOrEmpty
}

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
Loading

0 comments on commit fca3e16

Please sign in to comment.