Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Optimized integration test performance by leaving the DSCSQLTEST service running
for subsequent tests, significantly improving CI build times.
- Improved code quality by ensuring all function invocations in the private
and public functions use named parameters instead of positional parameters.
- SqlServerDsc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ AfterAll {

Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

Expand All @@ -63,9 +60,6 @@ Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S

# Disconnect from the SQL Server
Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When operator exists' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@ BeforeAll {

Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:instanceName = 'DSCSQLTEST'
$script:computerName = Get-ComputerName
}

AfterAll {
# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When connecting to SQL Server instance' {
BeforeAll {
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integrati

Context 'When connecting to a named instance' {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization
}

AfterAll {
# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
# Note: SQL Server service is left running for subsequent tests for performance optimization
}

It 'Should have the named instance SQL Server service started' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'

$mockSqlAdministratorUserName = 'SqlAdmin'
Expand All @@ -46,23 +43,19 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When converting empty collection of DatabasePermissionInfo' {
It 'Should return empty array for empty DatabasePermissionInfo collection' {
$emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @()

$result = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $emptyCollection

$result | Should -BeNullOrEmpty
}

It 'Should accept empty collection through pipeline' {
$emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @()

$result = $emptyCollection | ConvertTo-SqlDscDatabasePermission

$result | Should -BeNullOrEmpty
Expand All @@ -80,12 +73,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int

# Validate the result structure
$result | Should -Not -BeNullOrEmpty

# Each result should have State and Permission properties
foreach ($permission in $result) {
$permission.State | Should -Not -BeNullOrEmpty
$permission.Permission | Should -Not -BeNullOrEmpty

# Validate that permission state is one of the expected values
$permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant')
}
Expand All @@ -102,12 +95,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int

# Validate the result structure
$result | Should -Not -BeNullOrEmpty

# Each result should have State and Permission properties
foreach ($permission in $result) {
$permission.State | Should -Not -BeNullOrEmpty
$permission.Permission | Should -Not -BeNullOrEmpty

# Validate that permission state is one of the expected values
$permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant')
}
Expand All @@ -126,12 +119,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int

# Validate the result structure
$result | Should -Not -BeNullOrEmpty

# Each result should have State and Permission properties
foreach ($permission in $result) {
$permission.State | Should -Not -BeNullOrEmpty
$permission.Permission | Should -Not -BeNullOrEmpty

# Validate that permission state is one of the expected values
$permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant')
}
Expand All @@ -151,7 +144,7 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int
if ($result) {
# Validate that permissions are properly grouped by state
$uniqueStates = $result.State | Sort-Object -Unique

foreach ($state in $uniqueStates) {
$permissionsForState = $result | Where-Object { $_.State -eq $state }
$permissionsForState | Should -HaveCount 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
Expand All @@ -50,9 +47,6 @@ Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integratio

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When denying server permissions to login' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ AfterAll {

Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
$mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword)
Expand All @@ -61,9 +58,6 @@ Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_
Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop'

Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stopping the named instance SQL Server service after running tests.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When disabling an existing agent operator' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'
$script:mockComputerName = Get-ComputerName

Expand All @@ -47,9 +44,6 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When disabling an audit using ServerObject parameter set' {
Expand Down Expand Up @@ -206,7 +200,7 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201
'SqlDscTestMultiDisable1_' + (Get-Random),
'SqlDscTestMultiDisable2_' + (Get-Random)
)

foreach ($auditName in $script:testAuditNames)
{
$null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
Expand All @@ -49,9 +46,6 @@ Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL201

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When disabling a login using ServerObject parameter set' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ AfterAll {

Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
$mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword)
Expand All @@ -61,9 +58,6 @@ Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S
Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop'

Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stopping the named instance SQL Server service after running tests.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When enabling an existing agent operator' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
Expand All @@ -49,9 +46,6 @@ Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When enabling a login using ServerObject parameter set' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ Describe 'Get-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20
# Integration tests are run on the DSCSQLTEST instance
$script:sqlServerInstance = 'DSCSQLTEST'

# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
# Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
Expand Down Expand Up @@ -75,9 +74,6 @@ END

# Disconnect from the SQL Server
Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

It 'Should get all alerts' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ AfterAll {

Describe 'Get-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

Expand All @@ -65,9 +62,6 @@ Describe 'Get-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2

# Disconnect from the SQL Server
Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

It 'Should get all operators' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
Expand All @@ -46,9 +43,6 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When getting all configuration options' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Get-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'
$script:mockComputerName = Get-ComputerName

Expand All @@ -47,9 +44,6 @@ Describe 'Get-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019

AfterAll {
Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject

# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}

Context 'When getting all SQL Server databases' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ BeforeAll {

Describe 'Get-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
# Starting the named instance SQL Server service prior to running tests.
Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'

$script:mockInstanceName = 'DSCSQLTEST'

$mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
Expand All @@ -44,12 +41,6 @@ Describe 'Get-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019',
$script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential
}

AfterAll {
# Stop the named instance SQL Server service to save memory on the build worker.
Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
}


Context 'When getting all SQL Server logins' {
It 'Should return an array of Login objects' {
$result = Get-SqlDscLogin -ServerObject $script:serverObject
Expand Down
Loading
Loading