Skip to content

Commit

Permalink
Connect-SqlDscDatabaseEngine: Added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed May 18, 2024
1 parent 56d2940 commit fc470c5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `Connect-SqlDscDatabaseEngine`
- Added integration test for the command.

### Fixed

- `Connect-SqlDscDatabaseEngine`
- Comment-based help for parameter `LoginType` was corrected.
- An integration test now runs to test the command.

## [16.6.0] - 2024-05-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion source/Public/Connect-SqlDscDatabaseEngine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
are 'WindowsUser' or 'SqlLogin'. Default value is 'WindowsUser'
If set to 'WindowsUser' then the it will impersonate using the Windows
login specified in the parameter Credential.
If set to 'WindowsUser' then the it will impersonate using the native SQL
If set to 'SqlLogin' then it will impersonate using the native SQL
login specified in the parameter Credential.
.PARAMETER StatementTimeout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
try
{
if (-not (Get-Module -Name 'DscResource.Test'))
{
# Assumes dependencies has been resolved, so if this module is not available, run 'noop' task.
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
{
# Redirect all streams to $null, except the error stream (stream 2)
& "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null
}

# If the dependencies has not been resolved, this will throw an error.
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
}
}
catch [System.IO.FileNotFoundException]
{
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
}
}

Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
BeforeAll {
Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose

$computerName = Get-ComputerName
}

Context 'When connecting to the default instance impersonating a Windows user' {
It 'Should return the correct result' {
{
$sqlAdministratorUserName = '{0}\SqlAdmin' -f $computerName
$sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force

$connectSqlDscDatabaseEngineParameters = @{
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ BeforeDiscovery {
}

Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
# BeforeAll {
BeforeAll {
Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose

# # Get the built SqlServerDsc module path.
# $modulePath = Split-Path -Parent -Path (Get-Module -name SqlServerDsc -ListAvailable).ModuleBase
# }
}

Context 'When using Install parameter set' {
Context 'When installing database engine default instance' {
It 'Should run the command without throwing' {
{
Write-Verbose -Message ('Running install as user ''{0}''.' -f $env:UserName) -Verbose

$computerName = Get-ComputerName

# Set splatting parameters for Install-SqlDscServer
Expand Down

0 comments on commit fc470c5

Please sign in to comment.