-
Notifications
You must be signed in to change notification settings - Fork 227
Add integration test for Get-SqlDscStartupParameter command #2249
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a7fc3d9
Initial plan
Copilot 3e4e41a
Add integration test for Get-SqlDscStartupParameter command
Copilot fd46497
Merge branch 'main' into copilot/fix-2217
johlju 602b096
Update integration test for Get-SqlDscStartupParameter to use test in…
johlju b53e73b
Fix integration test feedback: change task to noop, remove service st…
Copilot 4f5a529
Fix StartupParameters type access using InModuleScope for integration…
Copilot c147f52
Add -ModuleName parameter to all InModuleScope calls in integration test
Copilot dc199a0
Update documentation in Get-SqlDscStartupParameter to clarify paramet…
johlju eaffdcd
Merge branch 'main' into copilot/fix-2217
johlju b7e83a6
Add test for pipeline input handling in Get-SqlDscStartupParameter
johlju 5564476
Refactor error handling and parameter processing in Get-SqlDscStartup…
johlju 87409d8
Enhance tests in Get-SqlDscStartupParameter to handle single-element …
johlju bde0611
Refactor tests in Get-SqlDscStartupParameter to simplify type checks …
johlju ef9f351
Merge branch 'main' into copilot/fix-2217
johlju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
tests/Integration/Commands/Get-SqlDscStartupParameter.Integration.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| [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 have 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' 3>&1 4>&1 5>&1 6>&1 > $null | ||
| } | ||
|
|
||
| # If the dependencies have 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 noop" first.' | ||
| } | ||
| } | ||
|
|
||
| BeforeAll { | ||
| $script:moduleName = 'SqlServerDsc' | ||
|
|
||
| Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| # cSpell: ignore DSCSQLTEST | ||
| Describe 'Get-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { | ||
| BeforeAll { | ||
| Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose | ||
|
|
||
| $script:mockInstanceName = 'DSCSQLTEST' | ||
| $script:mockServerName = Get-ComputerName | ||
| } | ||
|
|
||
| Context 'When using parameter set ByServerName' { | ||
| Context 'When getting startup parameters with default parameters' { | ||
| It 'Should return a StartupParameters object for the test instance' { | ||
| $result = Get-SqlDscStartupParameter -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
|
|
||
| $result | Should -Not -BeNullOrEmpty | ||
| $result | Should -BeOfType ([StartupParameters]) | ||
| $result.DataFilePath | Should -Not -BeNullOrEmpty | ||
| $result.LogFilePath | Should -Not -BeNullOrEmpty | ||
| $result.ErrorLogPath | Should -Not -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context 'When getting startup parameters for a specific instance' { | ||
| It 'Should return a StartupParameters object for the specified instance' { | ||
| $result = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
|
|
||
| $result | Should -Not -BeNullOrEmpty | ||
| $result | Should -BeOfType ([StartupParameters]) | ||
| $result.DataFilePath | Should -Not -BeNullOrEmpty | ||
| $result.LogFilePath | Should -Not -BeNullOrEmpty | ||
| $result.ErrorLogPath | Should -Not -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context 'When getting startup parameters for a specific server name' { | ||
| It 'Should return a StartupParameters object for the specified server' { | ||
| $result = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
|
|
||
| $result | Should -Not -BeNullOrEmpty | ||
| $result | Should -BeOfType ([StartupParameters]) | ||
| $result.DataFilePath | Should -Not -BeNullOrEmpty | ||
| $result.LogFilePath | Should -Not -BeNullOrEmpty | ||
| $result.ErrorLogPath | Should -Not -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context 'When getting startup parameters for a non-existent instance' { | ||
| It 'Should throw an error when the instance does not exist' { | ||
| { | ||
| Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName 'NonExistentInstance' -ErrorAction 'Stop' | ||
| } | Should -Throw -ErrorId 'GSDSP0001,Get-SqlDscStartupParameter' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Context 'When using parameter set ByServiceObject' { | ||
| BeforeAll { | ||
| $script:serviceObject = Get-SqlDscManagedComputerService -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ServiceType 'DatabaseEngine' -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| Context 'When getting startup parameters using a service object' { | ||
| It 'Should return a StartupParameters object for the service object' { | ||
| $result = Get-SqlDscStartupParameter -ServiceObject $script:serviceObject -ErrorAction 'Stop' | ||
|
|
||
| $result | Should -Not -BeNullOrEmpty | ||
| $result | Should -BeOfType ([StartupParameters]) | ||
| $result.DataFilePath | Should -Not -BeNullOrEmpty | ||
| $result.LogFilePath | Should -Not -BeNullOrEmpty | ||
| $result.ErrorLogPath | Should -Not -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context 'When getting startup parameters using pipeline input' { | ||
| It 'Should accept ServiceObject from pipeline and return StartupParameters' { | ||
| $result = $script:serviceObject | Get-SqlDscStartupParameter -ErrorAction 'Stop' | ||
|
|
||
| $result | Should -Not -BeNullOrEmpty | ||
| $result | Should -BeOfType ([StartupParameters]) | ||
| $result.DataFilePath | Should -Not -BeNullOrEmpty | ||
| $result.LogFilePath | Should -Not -BeNullOrEmpty | ||
| $result.ErrorLogPath | Should -Not -BeNullOrEmpty | ||
| } | ||
| } | ||
|
|
||
| Context 'When passing wrong service type' { | ||
| BeforeAll { | ||
| # Get a non-DatabaseEngine service for testing | ||
| $script:wrongServiceObject = Get-SqlDscManagedComputerService -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ServiceType 'SqlServerAgent' -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| It 'Should throw an error when the service type is not DatabaseEngine' { | ||
| { | ||
| Get-SqlDscStartupParameter -ServiceObject $script:wrongServiceObject -ErrorAction 'Stop' | ||
| } | Should -Throw | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Context 'When validating output properties' { | ||
| BeforeAll { | ||
| $script:result = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| It 'Should return an object with expected DataFilePath property' { | ||
| $script:result.DataFilePath | Should -Not -BeNullOrEmpty | ||
| $script:result.DataFilePath | Should -BeOfType ([System.String[]]) | ||
| $script:result.DataFilePath[0] | Should -Match '\.mdf$' | ||
| } | ||
|
|
||
| It 'Should return an object with expected LogFilePath property' { | ||
| $script:result.LogFilePath | Should -Not -BeNullOrEmpty | ||
| $script:result.LogFilePath | Should -BeOfType ([System.String[]]) | ||
| $script:result.LogFilePath[0] | Should -Match '\.ldf$' | ||
| } | ||
|
|
||
| It 'Should return an object with expected ErrorLogPath property' { | ||
| $script:result.ErrorLogPath | Should -Not -BeNullOrEmpty | ||
| $script:result.ErrorLogPath | Should -BeOfType ([System.String[]]) | ||
| $script:result.ErrorLogPath[0] | Should -Match 'ERRORLOG$' | ||
| } | ||
|
|
||
| It 'Should return TraceFlag property as an array' { | ||
| $script:result.TraceFlag | Should -BeOfType ([System.UInt32[]]) | ||
| } | ||
|
|
||
| It 'Should return InternalTraceFlag property as an array' { | ||
| $script:result.InternalTraceFlag | Should -BeOfType ([System.UInt32[]]) | ||
| } | ||
| } | ||
|
|
||
| Context 'When comparing results from different parameter sets' { | ||
| It 'Should return the same results for ByServerName and ByServiceObject parameter sets' { | ||
| $resultByServerName = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
|
|
||
| $serviceObject = Get-SqlDscManagedComputerService -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ServiceType 'DatabaseEngine' -ErrorAction 'Stop' | ||
| $resultByServiceObject = Get-SqlDscStartupParameter -ServiceObject $serviceObject -ErrorAction 'Stop' | ||
|
|
||
| $resultByServerName.DataFilePath | Should -Be $resultByServiceObject.DataFilePath | ||
| $resultByServerName.LogFilePath | Should -Be $resultByServiceObject.LogFilePath | ||
| $resultByServerName.ErrorLogPath | Should -Be $resultByServiceObject.ErrorLogPath | ||
| $resultByServerName.TraceFlag | Should -Be $resultByServiceObject.TraceFlag | ||
| $resultByServerName.InternalTraceFlag | Should -Be $resultByServiceObject.InternalTraceFlag | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.