-
Notifications
You must be signed in to change notification settings - Fork 227
Add integration test for Remove-SqlDscTraceFlag #2245
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 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
22eaab2
Initial plan
Copilot 93ba4c2
Add integration test for Remove-SqlDscTraceFlag command
Copilot 22bfdd9
Update README.md to include Remove-SqlDscTraceFlag integration test
Copilot c7ce600
Fix parameter binding error in Add-SqlDscTraceFlag and Remove-SqlDscT…
Copilot e7699bd
Merge branch 'main' into copilot/fix-2239
johlju c9cff28
Add blank line at end of Remove-SqlDscTraceFlag integration test file
Copilot 17e62ba
Fix typo in parameter name for Get-SqlDscTraceFlag function
johlju 96ee82a
Update build and test workflow requirements to include coverage options
johlju b78e110
Refine Build & Test Workflow guidelines for clarity on VS Code usage
johlju 8833d14
Fix typo in parameter name for TraceFlag in Remove-SqlDscTraceFlag fu…
johlju 28d8fd8
Optimize Remove-SqlDscTraceFlag to skip unnecessary Set operations wh…
johlju 93224a3
Update test scripts to reference 'noop' task for dependency resolution
johlju d769033
Merge branch 'main' into copilot/fix-2239
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
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
159 changes: 159 additions & 0 deletions
159
tests/Integration/Commands/Remove-SqlDscTraceFlag.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,159 @@ | ||
| [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 build" first.' | ||
| } | ||
| } | ||
|
|
||
| BeforeAll { | ||
| $script:moduleName = 'SqlServerDsc' | ||
|
|
||
| Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' | ||
| } | ||
|
|
||
| Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { | ||
| BeforeAll { | ||
| $script:mockInstanceName = 'DSCSQLTEST' | ||
| $script:mockComputerName = Get-ComputerName | ||
|
|
||
| # Test trace flags to use for testing | ||
| $script:testTraceFlags = @(4199, 3226) | ||
| $script:singleTestTraceFlag = 1118 | ||
| } | ||
|
|
||
| Context 'When removing trace flags using ServerName and InstanceName parameters' { | ||
| It 'Should remove a single trace flag without error' { | ||
| # Arrange - Add a test trace flag first | ||
| { | ||
| Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Act - Remove the trace flag | ||
| { | ||
| Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Assert - Verify the trace flag was removed | ||
| $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
| $currentTraceFlags | Should -Not -Contain $script:singleTestTraceFlag | ||
| } | ||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| It 'Should remove multiple trace flags without error' { | ||
| # Arrange - Add test trace flags first | ||
| { | ||
| Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Act - Remove the trace flags | ||
| { | ||
| Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Assert - Verify the trace flags were removed | ||
| $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
| foreach ($traceFlag in $script:testTraceFlags) | ||
| { | ||
| $currentTraceFlags | Should -Not -Contain $traceFlag | ||
| } | ||
| } | ||
|
|
||
| It 'Should not error when removing non-existent trace flags' { | ||
| # Act & Assert - Removing a trace flag that doesn't exist should not throw | ||
| { | ||
| Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag 9999 -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
| } | ||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| It 'Should preserve other existing trace flags when removing specific ones' { | ||
| # Arrange - Add multiple trace flags | ||
| $allTestFlags = @(4199, 3226, 1118, 2544) | ||
| $flagsToRemove = @(4199, 1118) | ||
| $flagsToKeep = @(3226, 2544) | ||
|
|
||
| { | ||
| Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $allTestFlags -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Act - Remove only some of the trace flags | ||
| { | ||
| Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $flagsToRemove -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Assert - Verify correct flags were removed and others preserved | ||
| $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
|
|
||
| foreach ($removedFlag in $flagsToRemove) | ||
| { | ||
| $currentTraceFlags | Should -Not -Contain $removedFlag | ||
| } | ||
|
|
||
| foreach ($keptFlag in $flagsToKeep) | ||
| { | ||
| $currentTraceFlags | Should -Contain $keptFlag | ||
| } | ||
|
|
||
| # Clean up - Remove remaining test flags | ||
| Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $flagsToKeep -Force -ErrorAction 'SilentlyContinue' | ||
| } | ||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Context 'When removing trace flags using ServiceObject parameter' { | ||
| BeforeAll { | ||
| # Get the service object for the test instance | ||
| $script:serviceObject = Get-SqlDscManagedComputerService -ServiceType 'DatabaseEngine' -InstanceName $script:mockInstanceName -ErrorAction 'Stop' | ||
| } | ||
|
|
||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| It 'Should remove a single trace flag using ServiceObject parameter' { | ||
| # Arrange - Add a test trace flag first | ||
| { | ||
| Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Act - Remove the trace flag | ||
| { | ||
| Remove-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Assert - Verify the trace flag was removed | ||
| $currentTraceFlags = Get-SqlDscTraceFlag -ServiceObject $script:serviceObject -ErrorAction 'Stop' | ||
| $currentTraceFlags | Should -Not -Contain $script:singleTestTraceFlag | ||
| } | ||
|
|
||
| It 'Should remove multiple trace flags using ServiceObject parameter' { | ||
| # Arrange - Add test trace flags first | ||
| { | ||
| Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
| # Act - Remove the trace flags | ||
| { | ||
| Remove-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' | ||
| } | Should -Not -Throw | ||
|
|
||
johlju marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Assert - Verify the trace flags were removed | ||
| $currentTraceFlags = Get-SqlDscTraceFlag -ServiceObject $script:serviceObject -ErrorAction 'Stop' | ||
| foreach ($traceFlag in $script:testTraceFlags) | ||
| { | ||
| $currentTraceFlags | Should -Not -Contain $traceFlag | ||
| } | ||
| } | ||
| } | ||
| } | ||
johlju marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
johlju marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
johlju marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.