diff --git a/CHANGELOG.md b/CHANGELOG.md index 506ce654b..fdae13468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/source/Public/Connect-SqlDscDatabaseEngine.ps1 b/source/Public/Connect-SqlDscDatabaseEngine.ps1 index d4071296e..53fc2d0b0 100644 --- a/source/Public/Connect-SqlDscDatabaseEngine.ps1 +++ b/source/Public/Connect-SqlDscDatabaseEngine.ps1 @@ -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 diff --git a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 new file mode 100644 index 000000000..6fdd96a4e --- /dev/null +++ b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -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 + } + } +} diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index f14b2c486..9f1b0f559 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -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