Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlServerDsc: Pester 6 format #2035

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- SqlSetup
- Added new parameter ProductCoveredbySA which is introduced in SQL 2022.
- Added new parameter ProductCoveredBySA which is introduced in SQL 2022.

### Added

Expand All @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SqlServerDsc
- Replaced inline task `Package_Wiki_Content` with the one now available
in the module _DscResource.DocGenerator_.
- Update tests to Pester 6 format.
- `Connect-SqlDscDatabaseEngine`
- Update comment-based help with more examples.
- SqlSetup
Expand Down
4 changes: 2 additions & 2 deletions Resolve-Dependency.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
AllowPrerelease = $false
WithYAML = $true

#UseModuleFast = $true
UseModuleFast = $true
#ModuleFastVersion = '0.1.2'
#ModuleFastBleedingEdge = $true

UsePSResourceGet = $true
#UsePSResourceGet = $true
#PSResourceGetVersion = '1.0.1'

UsePowerShellGetCompatibilityModule = $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,23 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati
It 'Should have the default instance SQL Server service started' {
$getServiceResult = Get-Service -Name 'MSSQLSERVER' -ErrorAction 'Stop'

$getServiceResult.Status | Should -Be 'Running'
$getServiceResult.Status | Should-Be 'Running'
}

Context 'When impersonating a Windows user' {
It 'Should return the correct result' {
{
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

$connectSqlDscDatabaseEngineParameters = @{
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
Verbose = $true
ErrorAction = 'Stop'
}
$connectSqlDscDatabaseEngineParameters = @{
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
Verbose = $true
ErrorAction = 'Stop'
}

$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters

$sqlServerObject.Status.ToString() | Should -Match '^Online$'
} | Should -Not -Throw
$sqlServerObject.Status.ToString() | Should-MatchString '^Online$'
}
}
}
Expand All @@ -91,47 +89,43 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati
It 'Should have the named instance SQL Server service started' {
$getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop'

$getServiceResult.Status | Should -Be 'Running'
$getServiceResult.Status | Should-Be 'Running'
}

Context 'When impersonating a Windows user' {
It 'Should return the correct result' {
{
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force
$sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

$connectSqlDscDatabaseEngineParameters = @{
InstanceName = 'DSCSQLTEST'
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
Verbose = $true
ErrorAction = 'Stop'
}
$connectSqlDscDatabaseEngineParameters = @{
InstanceName = 'DSCSQLTEST'
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
Verbose = $true
ErrorAction = 'Stop'
}

$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters

$sqlServerObject.Status.ToString() | Should -Match '^Online$'
} | Should -Not -Throw
$sqlServerObject.Status.ToString() | Should-MatchString '^Online$'
}
}

Context 'When using a SQL login' {
It 'Should return the correct result' {
{
$sqlAdministratorUserName = 'sa'
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

$connectSqlDscDatabaseEngineParameters = @{
InstanceName = 'DSCSQLTEST' # cSpell: disable-line
LoginType = 'SqlLogin'
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
Verbose = $true
ErrorAction = 'Stop'
}

$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters

$sqlServerObject.Status.ToString() | Should -Match '^Online$'
} | Should -Not -Throw
$sqlAdministratorUserName = 'sa'
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

$connectSqlDscDatabaseEngineParameters = @{
InstanceName = 'DSCSQLTEST' # cSpell: disable-line
LoginType = 'SqlLogin'
Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword)
Verbose = $true
ErrorAction = 'Stop'
}

$sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters

$sqlServerObject.Status.ToString() | Should-MatchString '^Online$'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
Context 'When using Install parameter set' {
Context 'When installing database engine default instance' {
It 'Should run the command without throwing' {
{
$null = & ({
# Set splatting parameters for Install-SqlDscServer
$installSqlDscServerParameters = @{
Install = $true
Expand Down Expand Up @@ -141,15 +141,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
# (Get-ComputerName),
# $modulePath
# )
} | Should -Not -Throw
})
}

It 'Should have installed the SQL Server database engine' {
# Validate the SQL Server installation
$sqlServerService = Get-Service -Name 'MSSQLSERVER'

$sqlServerService | Should -Not -BeNullOrEmpty
$sqlServerService.Status | Should -Be 'Running'
$sqlServerService | Should-BeTruthy
$sqlServerService.Status | Should-Be 'Running'
}

It 'Should stop the default instance SQL Server service' {
Expand All @@ -165,7 +165,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
#>
$stopServiceResult |
Where-Object -FilterScript { $_.Name -eq 'MSSQLSERVER'}
).Status | Should -Be 'Stopped'
).Status | Should-Be 'Stopped'
}
}

Expand All @@ -176,7 +176,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
# }

It 'Should run the command without throwing' {
{
$null = & ({
# Set splatting parameters for Install-SqlDscServer
$installSqlDscServerParameters = @{
Install = $true
Expand Down Expand Up @@ -285,15 +285,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
# $modulePath
# )
# } | Should -Not -Throw
} | Should -Not -Throw
})
}

It 'Should have installed the SQL Server database engine' {
# Validate the SQL Server installation
$sqlServerService = Get-Service -Name 'MSSQL$DSCSQLTEST'

$sqlServerService | Should -Not -BeNullOrEmpty
$sqlServerService.Status | Should -Be 'Running'
$sqlServerService | Should-BeTruthy
$sqlServerService.Status | Should-Be 'Running'
}

It 'Should stop the named instance SQL Server service' {
Expand All @@ -307,7 +307,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20
#>
$stopServiceResult |
Where-Object -FilterScript { $_.Name -eq 'MSSQL$DSCSQLTEST' }
).Status | Should -Be 'Stopped'
).Status | Should-Be 'Stopped'
}
}

Expand Down
Loading
Loading