Skip to content

Commit a4ddc3e

Browse files
committed
Refactor Assert-SqlDscLogin tests to manage SQL Server service lifecycle and improve credential handling
1 parent c0e5b4a commit a4ddc3e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,25 @@ BeforeAll {
3131

3232
Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
3333
BeforeAll {
34+
# Starting the default instance SQL Server service prior to running tests.
35+
Start-Service -Name 'MSSQLSERVER' -Verbose -ErrorAction 'Stop'
36+
3437
$script:instanceName = 'DSCSQLTEST'
3538
$script:computerName = Get-ComputerName
3639
}
3740

41+
AfterAll {
42+
# Stop the default instance SQL Server service to save memory on the build worker.
43+
Stop-Service -Name 'MSSQLSERVER' -Verbose -ErrorAction 'Stop'
44+
}
45+
3846
Context 'When connecting to SQL Server instance' {
3947
BeforeAll {
40-
$script:sqlAdminCredential = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList @(
41-
('{0}\SqlAdmin' -f (Get-ComputerName)),
42-
('P@ssw0rd1' | ConvertTo-SecureString -AsPlainText -Force)
43-
)
48+
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
49+
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
50+
51+
$script:sqlAdminCredential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
52+
4453
$script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:instanceName -Credential $script:sqlAdminCredential
4554
}
4655

0 commit comments

Comments
 (0)