diff --git a/.github/instructions/SqlServerDsc-guidelines.instructions.md b/.github/instructions/SqlServerDsc-guidelines.instructions.md index 12677a9144..c03e1d867c 100644 --- a/.github/instructions/SqlServerDsc-guidelines.instructions.md +++ b/.github/instructions/SqlServerDsc-guidelines.instructions.md @@ -37,7 +37,6 @@ applyTo: "**" ## Tests Requirements - Unit tests: Add `$env:SqlServerDscCI = $true` in `BeforeAll`, remove in `AfterAll` - Integration tests: - - If requiring SQL Server DB, start the Windows service in `BeforeAll`, stop it in `AfterAll`. - Use `Connect-SqlDscDatabaseEngine` for SQL Server DB session, and always with correct CI credentials - Use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine` - Test config: tests/Integration/Commands/README.md and tests/Integration/Resources/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a77eaabb..284b9a04d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 index 2454fdf707..d55ac7c122 100644 --- a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 @@ -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 @@ -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' { diff --git a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 index 88e35ae40a..1db9150763 100644 --- a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 @@ -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. diff --git a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 index 5a878651f8..cbc56489cc 100644 --- a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -84,16 +84,6 @@ 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' - } - - AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - } - It 'Should have the named instance SQL Server service started' { $getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' diff --git a/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 index 940dad3989..57264ee7af 100644 --- a/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -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' @@ -46,15 +43,11 @@ 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 @@ -62,7 +55,7 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int It 'Should accept empty collection through pipeline' { $emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @() - + $result = $emptyCollection | ConvertTo-SqlDscDatabasePermission $result | Should -BeNullOrEmpty @@ -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') } @@ -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') } @@ -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') } @@ -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 diff --git a/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 index d659811579..6e84e499a8 100644 --- a/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 @@ -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. @@ -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' { diff --git a/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 index 4e94a8362c..ce69ec373c 100644 --- a/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 @@ -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) @@ -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' { diff --git a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 index 6a78ce3f92..87ee6ac36d 100644 --- a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 @@ -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 @@ -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' { @@ -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 diff --git a/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 index ea47f91d31..c66194719c 100644 --- a/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 @@ -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. @@ -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' { diff --git a/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 index 36c37da923..e750e50ff3 100644 --- a/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 @@ -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) @@ -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' { diff --git a/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 index e834d5776e..868600301e 100644 --- a/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 @@ -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. @@ -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' { diff --git a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 index c9172260fe..cbdb1ab0db 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,9 +34,6 @@ 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' - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -75,9 +72,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' { diff --git a/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 index 837f1c593d..37f7b5903d 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 @@ -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 @@ -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' { diff --git a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 index 965e390f03..36f9ed4845 100644 --- a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -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. @@ -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' { @@ -85,8 +79,8 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result | Should -BeOfType 'PSCustomObject' $result.PSTypeNames[0] | Should -Be 'SqlDsc.ConfigurationOption' $result.Name | Should -Be 'Agent XPs' - $result.RunValue | Should -Be 0 - $result.ConfigValue | Should -Be 0 + $result.RunValue | Should -Be 1 + $result.ConfigValue | Should -Be 1 $result.Minimum | Should -Be 0 $result.Maximum | Should -Be 1 $result.IsDynamic | Should -BeTrue @@ -109,7 +103,7 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result = Get-SqlDscConfigurationOption -ServerObject $script:serverObject -Name '*XP*' @($result).Count | Should -BeGreaterOrEqual 1 - $result | Where-Object { $_.Name -eq 'Agent XPs' } | Should -Not -BeNullOrEmpty + $result | Where-Object -FilterScript { $_.Name -eq 'Agent XPs' } | Should -Not -BeNullOrEmpty } } @@ -120,8 +114,8 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' $result.DisplayName | Should -Be 'Agent XPs' - $result.RunValue | Should -Be 0 - $result.ConfigValue | Should -Be 0 + $result.RunValue | Should -Be 1 + $result.ConfigValue | Should -Be 1 } } @@ -143,7 +137,7 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType 'PSCustomObject' $result.Name | Should -Be 'Agent XPs' - $result.RunValue | Should -Be 0 + $result.RunValue | Should -Be 1 } } } diff --git a/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 index 52ed64dba9..01e619cdb2 100644 --- a/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 @@ -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 @@ -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' { diff --git a/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 index f835934ae2..24a8177b40 100644 --- a/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 @@ -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. @@ -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 diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 index 74a2de8c5c..68393b7d10 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 @@ -34,25 +34,9 @@ Describe 'Get-SqlDscManagedComputer' -Tag @('Integration_SQL2017', 'Integration_ BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - # Note: On Windows CI environment, this would start the SQL Server service - if (Get-Command -Name 'Start-Service' -ErrorAction 'SilentlyContinue') - { - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - } - $script:mockServerName = Get-ComputerName } - AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - # Note: On Windows CI environment, this would stop the SQL Server service - if (Get-Command -Name 'Stop-Service' -ErrorAction 'SilentlyContinue') - { - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - } - } - Context 'When using default parameters' { It 'Should return the managed computer object for the local computer' { $result = Get-SqlDscManagedComputer -ErrorAction 'Stop' diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 index b755ccfc5e..2842dbbfae 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 @@ -34,18 +34,10 @@ Describe 'Get-SqlDscManagedComputerInstance' -Tag @('Integration_SQL2017', 'Inte BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = 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 using parameter set ByServerName' { Context 'When getting a specific instance' { It 'Should return the correct server instance' { diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 index b8a6bede72..80f2953de1 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 @@ -34,18 +34,10 @@ Describe 'Get-SqlDscManagedComputerService' -Tag @('Integration_SQL2017', 'Integ BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = 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 using parameter set ByServerName' { Context 'When getting all services on the current managed computer' { It 'Should return all available services' { diff --git a/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 index c24529a9ba..0bc417f2b4 100644 --- a/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Get-SqlDscRole' -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. @@ -50,9 +47,6 @@ Describe 'Get-SqlDscRole' -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 roles' { diff --git a/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 index c1990a51ac..f15bbb35d7 100644 --- a/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Get-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. @@ -46,9 +43,6 @@ Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration 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 connecting to SQL Server instance' { diff --git a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 index 20bee68814..9a0632940a 100644 --- a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 @@ -34,18 +34,10 @@ Describe 'Get-SqlDscServerProtocol' -Tag @('Integration_SQL2017', 'Integration_S BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = 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 using parameter set ByServerName' { Context 'When getting a specific protocol' { It 'Should return TcpIp protocol information' { diff --git a/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 index 733b8ca238..657ebff9ab 100644 --- a/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Grant-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. @@ -50,9 +47,6 @@ Describe 'Grant-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integrati 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 granting server permissions to login' { diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index 71482d7583..c12ac317c8 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -302,18 +302,14 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL20 $sqlServerService.Status | Should -Be 'Running' } - It 'Should stop the named instance SQL Server service' { - # Stop the named instance SQL Server service to save memory on the build worker. - $stopServiceResult = Stop-Service -Name 'MSSQL$DSCSQLTEST' -Force -PassThru -Verbose -ErrorAction 'Stop' + It 'Should leave the named instance SQL Server service running for subsequent tests' { + # Leave the named instance SQL Server service running to avoid start/stop overhead in subsequent tests. + # The service will be stopped later in the test pipeline after all tests that require it have completed. + $sqlServerService = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' - ( - <# - Filter services. This will also have stopped the dependent - service 'SQL Server Agent (DSCSQLTEST)'. - #> - $stopServiceResult | - Where-Object -FilterScript { $_.Name -eq 'MSSQL$DSCSQLTEST' } - ).Status | Should -Be 'Stopped' + $sqlServerService.Status | Should -Be 'Running' + + Write-Verbose -Message 'MSSQL$DSCSQLTEST service left running for subsequent integration tests to improve performance' -Verbose } } diff --git a/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 b/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 index 7667790d9e..622769e1e9 100644 --- a/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Invoke-SqlDscQuery' -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 @@ -58,7 +55,7 @@ CREATE TABLE TestTable ( INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Test3', 300) "@ - + Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $createTableQuery -Force -ErrorAction 'Stop' } @@ -77,9 +74,6 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes } 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 executing a query using ServerObject parameter set' { diff --git a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 index d3a91335b1..9b0689fc0c 100644 --- a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,9 +34,6 @@ Describe 'New-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' - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -64,9 +61,6 @@ Describe 'New-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # 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 create alert with severity' { diff --git a/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 index bc205726a4..2c953c5446 100644 --- a/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,9 +43,6 @@ AfterAll { Describe 'New-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 @@ -64,9 +61,6 @@ Describe 'New-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 create the persistent operator for other tests to use' { diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 95745c26b5..a612d5ab33 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'New-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 @@ -54,9 +51,9 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', AfterAll { # Clean up any test audits that might remain - $testAudits = Get-SqlDscAudit -ServerObject $script:serverObject -ErrorAction 'SilentlyContinue' | + $testAudits = Get-SqlDscAudit -ServerObject $script:serverObject -ErrorAction 'SilentlyContinue' | Where-Object { $_.Name -like 'SqlDscTestAudit*' } - + foreach ($audit in $testAudits) { try @@ -76,9 +73,6 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', { Remove-Item -Path $script:testAuditPath -Recurse -Force -ErrorAction 'SilentlyContinue' } - - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When creating a new application log audit' { @@ -112,7 +106,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create a security log audit successfully' { $securityLogAuditName = 'SqlDscTestAudit_SecLog_' + (Get-Random) - + try { $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop @@ -341,7 +335,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should throw error when path does not exist for file audit' { $nonExistentPath = Join-Path -Path $env:TEMP -ChildPath 'NonExistentPath' - + { New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $nonExistentPath -Force -ErrorAction Stop } | Should -Throw } diff --git a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 index a9afedf4da..3083c90b6f 100644 --- a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'New-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 @@ -64,9 +61,6 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } 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 creating a new database' { diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index f96973d15f..df0473a833 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'New-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 @@ -43,11 +40,6 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:testWindowsGroupName = '{0}\SqlIntegrationTestGroup' -f $script: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' diff --git a/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 index cfe2f388b5..61f454bc9b 100644 --- a/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'New-SqlDscRole' -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 @@ -68,9 +65,6 @@ Describe 'New-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', ' } 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 creating a new SQL Server role' { diff --git a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 index 2a9e998f1b..35babc7248 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,9 +34,6 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # 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' - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -50,9 +47,6 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ AfterAll { # 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 removing by ServerObject' { diff --git a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 index 389cdec5e0..e7b0e0127d 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,9 +43,6 @@ AfterAll { Describe 'Remove-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) @@ -55,9 +52,6 @@ Describe 'Remove-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S AfterAll { 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 removing test agent operators' { diff --git a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 index 17b0c6fa7d..5cffc100c2 100644 --- a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Remove-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 @@ -47,9 +44,6 @@ Describe 'Remove-SqlDscAudit' -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 removing an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 index 4f564a6983..3302c61c87 100644 --- a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Remove-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 @@ -47,9 +44,6 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 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 removing a database using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 index ad6d0f669f..6f27e80512 100644 --- a/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Remove-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. @@ -46,9 +43,6 @@ Describe 'Remove-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 removing a SQL Server login by ServerObject and Name' { diff --git a/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 index 6b4ebdc954..83f107a413 100644 --- a/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Remove-SqlDscRole' -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 @@ -68,9 +65,6 @@ Describe 'Remove-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019' } 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 removing a SQL Server role by name' { diff --git a/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 index 7dc5edb629..192ea8ab55 100644 --- a/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Revoke-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. @@ -50,9 +47,6 @@ Describe 'Revoke-SqlDscServerPermission' -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 revoking server permissions from login' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 index 712d1b8183..66d0b8f409 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,9 +34,6 @@ Describe 'Set-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' - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -54,9 +51,6 @@ Describe 'Set-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # 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 update alert severity using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 index 7664b668a3..32c48b57e8 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,9 +43,6 @@ AfterAll { Describe 'Set-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 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAdministratorUserName, $mockSqlAdministratorPassword @@ -61,9 +58,6 @@ Describe 'Set-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2 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 updating an existing agent operator' { diff --git a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 index 3c9d43b4cb..8ce4488917 100644 --- a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-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 @@ -47,9 +44,6 @@ Describe 'Set-SqlDscAudit' -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 modifying an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 index 516ad49f8b..49296567cf 100644 --- a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-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. @@ -49,15 +46,12 @@ Describe 'Set-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat AfterAll { # Restore the original Agent XPs value - if ($script:originalAgentXPsValue) + if ($null -ne $script:originalAgentXPsValue) { Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value $script:originalAgentXPsValue.RunValue -Force -ErrorAction 'SilentlyContinue' } 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 setting Agent XPs configuration option' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 index 2363c2ef05..64b8b67e3f 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-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 @@ -68,9 +65,6 @@ Describe 'Set-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } 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 setting database properties using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 index 34cab2cf13..b53bc56cfe 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-SqlDscDatabaseDefault' -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 @@ -66,9 +63,6 @@ Describe 'Set-SqlDscDatabaseDefault' -Tag @('Integration_SQL2017', 'Integration_ AfterAll { # Disconnect from the database engine. 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 using the DatabaseObject parameter' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 index 3b1880f76a..13345ff84e 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-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' # Using computer name as NetBIOS name throw exception. @@ -45,14 +42,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integrati # Use existing persistent test database from New-SqlDscDatabase integration tests $script:testDatabaseName = 'SqlDscIntegrationTestDatabase' - + # Use existing persistent principals created by earlier integration tests $script:testLoginName = 'IntegrationTestSqlLogin' $script:testRoleName = 'SqlDscIntegrationTestRole_Persistent' # Ensure the test database exists $existingDatabase = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'SilentlyContinue' - + if (-not $existingDatabase) { $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' @@ -81,9 +78,6 @@ END $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $sqlQuery -Force -ErrorAction 'SilentlyContinue' 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 setting database permissions with Grant state' { @@ -128,7 +122,7 @@ END $permissions = Get-SqlDscDatabasePermission -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Name $script:testLoginName -ErrorAction 'Stop' $permissions | Should -Not -BeNullOrEmpty - + $connectPermission = $permissions | Where-Object { $_.PermissionState -eq 'Grant' -and $_.PermissionType.Connect -eq $true } $connectPermission | Should -Not -BeNullOrEmpty $connectPermission.PermissionType.Connect | Should -BeTrue diff --git a/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 index 9a40471da9..296f814865 100644 --- a/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-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. @@ -51,22 +48,19 @@ Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration AfterAll { # Restore the expected state for shared test login that other tests depend on $script:loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -ErrorAction 'Stop' - + # Revoke any permissions we may have set Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'ViewServerState' -Force -ErrorAction 'SilentlyContinue' Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'ViewAnyDatabase' -Force -ErrorAction 'SilentlyContinue' Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'ViewAnyDefinition' -Force -ErrorAction 'SilentlyContinue' Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'CreateAnyDatabase' -WithGrant -Force -ErrorAction 'SilentlyContinue' - + # Restore the expected permissions that other tests depend on # Based on Grant test setup and Test command ExactMatch test expectations Grant-SqlDscServerPermission -Login $script:loginObject -Permission @('ViewServerState') -Force -ErrorAction 'SilentlyContinue' Grant-SqlDscServerPermission -Login $script:loginObject -Permission @('ViewAnyDefinition') -Force -ErrorAction 'SilentlyContinue' 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 setting server permissions to Grant state for login' { @@ -239,4 +233,3 @@ Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration } } } - diff --git a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 index 9e5f54eef1..72517f8be0 100644 --- a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 @@ -34,9 +34,6 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName @@ -60,9 +57,6 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration Write-Warning -Message "Failed to restore original startup parameters: $($_.Exception.Message)" } } - - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When using parameter set ByServerName' { @@ -183,7 +177,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration # Verify the parameters haven't changed $newParams = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' - + # Compare arrays properly handling nulls/empty arrays if ($currentParams.TraceFlag -and $newParams.TraceFlag) { Compare-Object -ReferenceObject $currentParams.TraceFlag -DifferenceObject $newParams.TraceFlag | Should -BeNullOrEmpty diff --git a/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 index 7bcecad821..7df5f92a93 100644 --- a/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Set-SqlDscTraceFlag' -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:mockServerName = Get-ComputerName @@ -52,9 +49,6 @@ Describe 'Set-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 # Clear all trace flags if there were none originally Set-SqlDscTraceFlag -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -TraceFlag @() -Force -ErrorAction 'SilentlyContinue' } - - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When setting trace flags' { diff --git a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 index a61c2f9439..bbec097631 100644 --- a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 @@ -34,9 +34,6 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat # 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' - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -57,9 +54,6 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat # 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 checking severity' { diff --git a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 index b811d8692e..d9c89b7f98 100644 --- a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Test-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. @@ -49,15 +46,12 @@ Describe 'Test-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integra AfterAll { # Restore the original Agent XPs value - if ($script:originalAgentXPsValue) + if ($null -ne $script:originalAgentXPsValue) { Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value $script:originalAgentXPsValue.RunValue -Force -ErrorAction 'SilentlyContinue' } 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 testing Agent XPs configuration option' { diff --git a/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 index c5cc235896..0f73093962 100644 --- a/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Test-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 @@ -47,9 +44,6 @@ Describe 'Test-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject -ErrorAction 'Stop' - - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When testing database presence' { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 index be26d5723e..c4c9d5419c 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 @@ -34,9 +34,6 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # 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' - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -57,9 +54,6 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # 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 checking existence only' { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 index e4fa394b8d..044aa5b617 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 @@ -43,9 +43,6 @@ AfterAll { Describe 'Test-SqlDscIsAgentOperator' -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 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAdministratorUserName, $mockSqlAdministratorPassword @@ -55,9 +52,6 @@ Describe 'Test-SqlDscIsAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S AfterAll { 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 testing for an existing agent operator' { diff --git a/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 index 3ad1ea4c18..861e1808c0 100644 --- a/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Test-SqlDscIsLogin' -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. @@ -49,9 +46,6 @@ Describe 'Test-SqlDscIsLogin' -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 testing login existence using ServerObject parameter set' { @@ -101,7 +95,7 @@ Describe 'Test-SqlDscIsLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 # Test with Windows login (using SqlAdmin which should exist) $computerName = Get-ComputerName $windowsLoginName = "$computerName\SqlAdmin" - + $result = Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $windowsLoginName $result | Should -BeOfType [System.Boolean] diff --git a/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 index 83987ec851..bfc26dec12 100644 --- a/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Test-SqlDscIsLoginEnabled' -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. @@ -49,9 +46,6 @@ Describe 'Test-SqlDscIsLoginEnabled' -Tag @('Integration_SQL2017', 'Integration_ 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 testing login state using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 index acd7a3bd70..648217fdd1 100644 --- a/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Test-SqlDscIsRole' -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. @@ -49,9 +46,6 @@ Describe 'Test-SqlDscIsRole' -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 testing for existing system roles' { diff --git a/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 index 00cf5b1e66..a5a4d4c4c6 100644 --- a/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Test-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. @@ -50,9 +47,6 @@ Describe 'Test-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 testing server permissions for login' { diff --git a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 index 990cd08a71..a290d7b07a 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 @@ -33,9 +33,6 @@ BeforeAll { Describe 'Uninstall-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } It 'Should have the named instance SQL Server service started' {