Skip to content

Commit

Permalink
should never reassign global
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Oct 18, 2024
1 parent 36831fb commit ce83dc5
Show file tree
Hide file tree
Showing 15 changed files with 7 additions and 37 deletions.
2 changes: 0 additions & 2 deletions tests/Backup-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ Describe "Backup-DbaDatabase Unit Tests" -Tag 'UnitTests' {

Describe "Backup-DbaDatabase Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance1 = "localhost"
$global:instance2 = "localhost\SQL2019"
$global:appveyorlabrepo = "C:\github\appveyor-lab"
$global:DestBackupDir = 'C:\Temp\backups'
$global:random = Get-Random
Expand Down
4 changes: 0 additions & 4 deletions tests/Disable-DbaAgHadr.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ Describe "Disable-DbaAgHadr" {
}

Context "Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance3 = [Environment]::GetEnvironmentVariable('instance3')
}

AfterAll {
Enable-DbaAgHadr -SqlInstance $global:instance3 -Confirm:$false -Force
}
Expand Down
6 changes: 0 additions & 6 deletions tests/Get-DbaAgentSchedule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ Describe "Get-DbaAgentSchedule Unit Tests" -Tag 'UnitTests' {

Describe "Get-DbaAgentSchedule Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance2 = $env:COMPUTERNAME
$global:instance3 = $env:COMPUTERNAME

$server2 = Connect-DbaInstance -SqlInstance $global:instance2
$server3 = Connect-DbaInstance -SqlInstance $global:instance3

$null = New-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force
$null = New-DbaAgentSchedule -SqlInstance $global:instance2 -Schedule dbatoolsci_WeeklyTest -FrequencyType Weekly -FrequencyInterval 2 -FrequencyRecurrenceFactor 1 -StartTime 020000 -Force
$null = New-DbaAgentSchedule -SqlInstance $global:instance3 -Schedule dbatoolsci_MonthlyTest -FrequencyType Monthly -FrequencyInterval 10 -FrequencyRecurrenceFactor 1 -Force
Expand Down
2 changes: 1 addition & 1 deletion tests/Get-DbaPowerPlan.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Describe "Get-DbaPowerPlan" {

Context "Command actually works" {
BeforeDiscovery {
$global:instance2 = $global:instance2 # Ensure this variable is available in the discovery phase
. "$PSScriptRoot\constants.ps1"
}
It "Should return result for the server" {
$results = Get-DbaPowerPlan -ComputerName $global:instance2
Expand Down
2 changes: 1 addition & 1 deletion tests/New-DbaAgentAlertCategory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Describe "New-DbaAgentAlertCategory" {

Context "New Agent Alert Category is added properly" {
BeforeAll {
$global:instance2 = "localhost"
. "$PSScriptRoot\constants.ps1"
}

AfterAll {
Expand Down
4 changes: 0 additions & 4 deletions tests/New-DbaAgentJobCategory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ Describe "New-DbaAgentJobCategory" {
}

Context "New Agent Job Category is added properly" {
BeforeAll {
$global:instance2 = "localhost"
}

It "Should have the right name and category type" {
$results = New-DbaAgentJobCategory -SqlInstance $global:instance2 -Category CategoryTest1
$results.Name | Should -Be "CategoryTest1"
Expand Down
1 change: 0 additions & 1 deletion tests/New-DbaAgentOperator.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Describe "New-DbaAgentOperator" {
Context "New Agent Operator is added properly" {
BeforeAll {
$random = Get-Random
$global:instance2 = $env:COMPUTERNAME
$server2 = Connect-DbaInstance -SqlInstance $global:instance2
$email1 = "test1$($random)@test.com"
$email2 = "test2$($random)@test.com"
Expand Down
4 changes: 1 addition & 3 deletions tests/New-DbaXESmartReplay.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ param($ModuleName = 'dbatools')

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

Expand Down Expand Up @@ -43,7 +41,7 @@ Describe "New-DbaXESmartReplay" {

Describe "New-DbaXESmartReplay Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance2 = [Environment]::GetEnvironmentVariable("instance2")
. "$PSScriptRoot\constants.ps1"
}

Context "Creates a smart object" {
Expand Down
2 changes: 1 addition & 1 deletion tests/Remove-DbaAgentAlert.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Describe "Remove-DbaAgentAlert Unit Tests" -Tag 'UnitTests' {

Describe "Remove-DbaAgentAlert Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance2 = "localhost"
. "$PSScriptRoot\constants.ps1"
}

BeforeEach {
Expand Down
5 changes: 0 additions & 5 deletions tests/Remove-DbaFirewallRule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ Describe "Remove-DbaFirewallRule Integration Tests" -Tag "IntegrationTests" {
}

Context "Command actually works" {
BeforeAll {
$global:instance1 = $global:instance1
$global:instance2 = $global:instance2
}

It "Removes firewall rules" {
# This test is a placeholder and needs to be implemented
# when we have a proper way to create and remove firewall rules in a test environment
Expand Down
1 change: 0 additions & 1 deletion tests/Restore-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ Describe "Restore-DbaDatabase Unit Tests" -Tag 'UnitTests' {

Describe "Restore-DbaDatabase Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance2 = "localhost"
$env:appveyorlabrepo = "C:\github\appveyor-lab"
$DataFolder = 'C:\temp\datafiles'
$LogFolder = 'C:\temp\logfiles'
Expand Down
2 changes: 1 addition & 1 deletion tests/Restore-DbaDbSnapshot.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Describe "Restore-DbaDbSnapshot Unit Tests" -Tag 'UnitTests' {

Describe "Restore-DbaDbSnapshot Integration Tests" -Tag "IntegrationTests" {
BeforeAll {
$global:instance2 = $global:instance2
. "$PSScriptRoot\constants.ps1"

Get-DbaProcess -SqlInstance $global:instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false -WarningAction SilentlyContinue
$server = Connect-DbaInstance -SqlInstance $global:instance2
Expand Down
4 changes: 0 additions & 4 deletions tests/Test-DbaDbLogShipStatus.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ Describe "Test-DbaDbLogShipStatus Unit Tests" -Tag "UnitTests" {
Describe "Test-DbaDbLogShipStatus Integration Tests" -Tag "IntegrationTests" {
BeforeDiscovery {
$env:skipIntegrationTests = $false
$global:instance1 = $null
$global:instance2 = $null

try {
. "$PSScriptRoot\constants.ps1"
$global:instance1 = $global:instance1
$global:instance2 = $global:instance2
} catch {
$env:skipIntegrationTests = $true
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Test-DbaDiskAllocation.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Describe "Test-DbaDiskAllocation" {

Context "Command actually works" {
BeforeDiscovery {
$global:instance2 = $global:instance2 # Ensure this variable is in scope for discovery
. "$PSScriptRoot\constants.ps1"
}
It "Should return a result" {
$results = Test-DbaDiskAllocation -ComputerName $global:instance2
Expand Down
3 changes: 1 addition & 2 deletions tests/Test-DbaMaxDop.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ param($ModuleName = 'dbatools')

Describe "Test-DbaMaxDop" {
BeforeAll {
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
. "$PSScriptRoot\constants.ps1"
}

Expand All @@ -23,7 +22,7 @@ Describe "Test-DbaMaxDop" {

Context "Command usage" {
BeforeDiscovery {
$global:instance2 = $global:instance2
. "$PSScriptRoot\constants.ps1"
}

BeforeAll {
Expand Down

0 comments on commit ce83dc5

Please sign in to comment.