Skip to content

Commit 2a5d1ce

Browse files
committed
Refactor integration tests to remove unnecessary comments about SQL Server service state
- Removed comments indicating that the SQL Server service is already running for performance optimization from multiple integration test files. - Cleaned up AfterAll sections to enhance readability and maintainability of the test scripts.
1 parent 3c9978f commit 2a5d1ce

File tree

53 files changed

+21
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+21
-234
lines changed

tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ AfterAll {
4343

4444
Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
4545
BeforeAll {
46-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
47-
4846
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
4947
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
5048

@@ -62,8 +60,6 @@ Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S
6260

6361
# Disconnect from the SQL Server
6462
Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject
65-
66-
# Note: SQL Server service is left running for subsequent tests for performance optimization
6763
}
6864

6965
Context 'When operator exists' {

tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,10 @@ BeforeAll {
3131

3232
Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
35-
3634
$script:instanceName = 'DSCSQLTEST'
3735
$script:computerName = Get-ComputerName
3836
}
3937

40-
AfterAll {
41-
# Note: SQL Server service is left running for subsequent tests for performance optimization
42-
}
43-
4438
Context 'When connecting to SQL Server instance' {
4539
BeforeAll {
4640
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.

tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ BeforeAll {
3131

3232
Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
35-
3634
$script:mockInstanceName = 'DSCSQLTEST'
3735

3836
$mockSqlAdministratorUserName = 'SqlAdmin'
@@ -45,22 +43,19 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int
4543

4644
AfterAll {
4745
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
48-
49-
# Note: SQL Server service is left running for subsequent tests for performance optimization
5046
}
51-
5247
Context 'When converting empty collection of DatabasePermissionInfo' {
5348
It 'Should return empty array for empty DatabasePermissionInfo collection' {
5449
$emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @()
55-
50+
5651
$result = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $emptyCollection
5752

5853
$result | Should -BeNullOrEmpty
5954
}
6055

6156
It 'Should accept empty collection through pipeline' {
6257
$emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @()
63-
58+
6459
$result = $emptyCollection | ConvertTo-SqlDscDatabasePermission
6560

6661
$result | Should -BeNullOrEmpty
@@ -78,12 +73,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int
7873

7974
# Validate the result structure
8075
$result | Should -Not -BeNullOrEmpty
81-
76+
8277
# Each result should have State and Permission properties
8378
foreach ($permission in $result) {
8479
$permission.State | Should -Not -BeNullOrEmpty
8580
$permission.Permission | Should -Not -BeNullOrEmpty
86-
81+
8782
# Validate that permission state is one of the expected values
8883
$permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant')
8984
}
@@ -100,12 +95,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int
10095

10196
# Validate the result structure
10297
$result | Should -Not -BeNullOrEmpty
103-
98+
10499
# Each result should have State and Permission properties
105100
foreach ($permission in $result) {
106101
$permission.State | Should -Not -BeNullOrEmpty
107102
$permission.Permission | Should -Not -BeNullOrEmpty
108-
103+
109104
# Validate that permission state is one of the expected values
110105
$permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant')
111106
}
@@ -124,12 +119,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int
124119

125120
# Validate the result structure
126121
$result | Should -Not -BeNullOrEmpty
127-
122+
128123
# Each result should have State and Permission properties
129124
foreach ($permission in $result) {
130125
$permission.State | Should -Not -BeNullOrEmpty
131126
$permission.Permission | Should -Not -BeNullOrEmpty
132-
127+
133128
# Validate that permission state is one of the expected values
134129
$permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant')
135130
}
@@ -149,7 +144,7 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int
149144
if ($result) {
150145
# Validate that permissions are properly grouped by state
151146
$uniqueStates = $result.State | Sort-Object -Unique
152-
147+
153148
foreach ($state in $uniqueStates) {
154149
$permissionsForState = $result | Where-Object { $_.State -eq $state }
155150
$permissionsForState | Should -HaveCount 1

tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ BeforeAll {
3131

3232
Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
35-
3634
$script:mockInstanceName = 'DSCSQLTEST'
3735

3836
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
@@ -49,8 +47,6 @@ Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integratio
4947

5048
AfterAll {
5149
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
52-
53-
# Note: SQL Server service is left running for subsequent tests for performance optimization
5450
}
5551

5652
Context 'When denying server permissions to login' {

tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ AfterAll {
4343

4444
Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
4545
BeforeAll {
46-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
47-
4846
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
4947
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
5048
$mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword)
@@ -60,9 +58,6 @@ Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_
6058
Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop'
6159

6260
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
63-
64-
# Stopping the named instance SQL Server service after running tests.
65-
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
6661
}
6762

6863
Context 'When disabling an existing agent operator' {

tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ BeforeAll {
3131

3232
Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
35-
3634
$script:mockInstanceName = 'DSCSQLTEST'
3735
$script:mockComputerName = Get-ComputerName
3836

@@ -46,8 +44,6 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201
4644

4745
AfterAll {
4846
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
49-
50-
# Note: SQL Server service is left running for subsequent tests for performance optimization
5147
}
5248

5349
Context 'When disabling an audit using ServerObject parameter set' {
@@ -204,7 +200,7 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201
204200
'SqlDscTestMultiDisable1_' + (Get-Random),
205201
'SqlDscTestMultiDisable2_' + (Get-Random)
206202
)
207-
203+
208204
foreach ($auditName in $script:testAuditNames)
209205
{
210206
$null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop

tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ BeforeAll {
3131

3232
Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
35-
3634
$script:mockInstanceName = 'DSCSQLTEST'
3735

3836
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
@@ -48,8 +46,6 @@ Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL201
4846

4947
AfterAll {
5048
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
51-
52-
# Note: SQL Server service is left running for subsequent tests for performance optimization
5349
}
5450

5551
Context 'When disabling a login using ServerObject parameter set' {

tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ AfterAll {
4343

4444
Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
4545
BeforeAll {
46-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
47-
4846
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
4947
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
5048
$mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword)
@@ -60,9 +58,6 @@ Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S
6058
Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop'
6159

6260
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
63-
64-
# Stopping the named instance SQL Server service after running tests.
65-
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
6661
}
6762

6863
Context 'When enabling an existing agent operator' {

tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ BeforeAll {
3131

3232
Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34-
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
35-
3634
$script:mockInstanceName = 'DSCSQLTEST'
3735

3836
$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
@@ -48,8 +46,6 @@ Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019
4846

4947
AfterAll {
5048
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
51-
52-
# Note: SQL Server service is left running for subsequent tests for performance optimization
5349
}
5450

5551
Context 'When enabling a login using ServerObject parameter set' {

tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ END
7474

7575
# Disconnect from the SQL Server
7676
Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject
77-
78-
# Note: SQL Server service is left running for subsequent tests for performance optimization
7977
}
8078

8179
It 'Should get all alerts' {

0 commit comments

Comments
 (0)