Skip to content

Commit 52e707f

Browse files
authored
Add integration test for Remove-SqlDscTraceFlag (#2245)
1 parent efabbdc commit 52e707f

File tree

240 files changed

+447
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+447
-276
lines changed

.github/instructions/SqlServerDsc-guidelines.instructions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ applyTo: "**"
66
# SqlServerDsc Requirements
77

88
## Build & Test Workflow Requirements
9-
- Run PowerShell script files from repository root
9+
- Never use VS Code task, always use PowerShell scripts via terminal, from repository root
1010
- Setup build and test environment (once per `pwsh` session): `./build.ps1 -Tasks noop`
1111
- Build project before running tests: `./build.ps1 -Tasks build`
1212
- Run tests without coverage (wildcards allowed): `Invoke-PesterJob -Path '{tests filepath}' -SkipCodeCoverage`
13+
- Run tests with coverage (wildcards allowed): `Invoke-PesterJob -Path '{tests filepath}' -EnableSourceLineMapping -FilterCodeCoverageResult '{pattern}'`
1314
- Run QA tests: `Invoke-PesterJob -Path 'tests/QA' -SkipCodeCoverage`
1415
- Never run integration tests locally
1516

CHANGELOG.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Added
99

10-
- Added integration tests for `Remove-SqlDscAudit` command to ensure it functions
11-
correctly in real environments
12-
[issue #2241](https://github.com/dsccommunity/SqlServerDsc/issues/2241).
10+
- `Remove-SqlDscTraceFlag`
11+
- Added missing integration test to ensure command reliability ([issue #2239](https://github.com/dsccommunity/SqlServerDsc/issues/2239)).
12+
- `Remove-SqlDscAudit`
13+
- Added missing integration test to ensure command reliability ([issue #2241](https://github.com/dsccommunity/SqlServerDsc/issues/2241)).
1314
- Added integration tests for `Test-SqlDscIsRole` command to ensure it functions
1415
correctly in real environments
1516
[issue #2229](https://github.com/dsccommunity/SqlServerDsc/issues/2229).
1617

1718
### Fixed
1819

20+
- `Add-SqlDscTraceFlag` and `Remove-SqlDscTraceFlag`
21+
- Fixed parameter binding error when `ErrorAction` was specified both
22+
explicitly and via `PSBoundParameters` by using `Remove-CommonParameter`
23+
instead of manual parameter removal
24+
([issue #2239](https://github.com/dsccommunity/SqlServerDsc/issues/2239)).
25+
- `Remove-SqlDscTraceFlag`
26+
- Optimized to skip unnecessary Set operations when removal results in no
27+
effective change
28+
([issue #2239](https://github.com/dsccommunity/SqlServerDsc/issues/2239)).
1929
- Updated `.gitattributes` to enforce LF line endings for PowerShell files to
2030
ensure cross-platform compatibility.
2131
- Updated GitHub Copilot setup workflow to fix environment variable assignment

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ stages:
333333
'tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1'
334334
'tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1'
335335
'tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1'
336+
'tests/Integration/Commands/Remove-SqlDscTraceFlag.Integration.Tests.ps1'
336337
# Group 9
337338
'tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1'
338339
)

source/Public/Add-SqlDscTraceFlag.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ function Add-SqlDscTraceFlag
9696
}
9797

9898
# Copy $PSBoundParameters to keep it intact.
99-
$getSqlDscTraceFlagParameters = @{} + $PSBoundParameters
99+
$getSqlDscTraceFlagParameters = Remove-CommonParameter -Hashtable $PSBoundParameters
100100

101-
$commonParameters = [System.Management.Automation.PSCmdlet]::OptionalCommonParameters
102-
103-
# Remove parameters that Get-SqlDscTraceFLag does not have/support.
104-
$commonParameters + @('Force', 'TraceFlag') |
101+
# Remove parameters that Get-SqlDscTraceFlag does not have/support.
102+
@('Force', 'TraceFlag') |
105103
ForEach-Object -Process {
106104
$getSqlDscTraceFlagParameters.Remove($_)
107105
}
@@ -132,9 +130,9 @@ function Add-SqlDscTraceFlag
132130
if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
133131
{
134132
# Copy $PSBoundParameters to keep it intact.
135-
$setSqlDscTraceFlagParameters = @{} + $PSBoundParameters
133+
$setSqlDscTraceFlagParameters = Remove-CommonParameter -Hashtable $PSBoundParameters
136134

137-
$setSqlDscTraceFlagParameters.TraceFLag = $desiredTraceFlags
135+
$setSqlDscTraceFlagParameters.TraceFlag = $desiredTraceFlags
138136

139137
$originalErrorActionPreference = $ErrorActionPreference
140138

source/Public/Remove-SqlDscTraceFlag.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ function Remove-SqlDscTraceFlag
9696
}
9797

9898
# Copy $PSBoundParameters to keep it intact.
99-
$getSqlDscTraceFlagParameters = @{} + $PSBoundParameters
99+
$getSqlDscTraceFlagParameters = Remove-CommonParameter -Hashtable $PSBoundParameters
100100

101-
$commonParameters = [System.Management.Automation.PSCmdlet]::OptionalCommonParameters
102-
103-
# Remove parameters that Get-SqlDscTraceFLag does not have/support.
104-
$commonParameters + @('Force', 'TraceFlag') |
101+
# Remove parameters that Get-SqlDscTraceFlag does not have/support.
102+
@('Force', 'TraceFlag') |
105103
ForEach-Object -Process {
106104
$getSqlDscTraceFlagParameters.Remove($_)
107105
}
@@ -128,16 +126,23 @@ function Remove-SqlDscTraceFlag
128126
}
129127
)
130128

129+
# Short-circuit if removal results in no effective change
130+
if (-not (Compare-Object -ReferenceObject $currentTraceFlags -DifferenceObject $desiredTraceFlags))
131+
{
132+
Write-Debug -Message $script:localizedData.TraceFlag_Remove_NoChange
133+
return
134+
}
135+
131136
$verboseDescriptionMessage = $script:localizedData.TraceFlag_Remove_ShouldProcessVerboseDescription -f $InstanceName, ($TraceFlag -join ', ')
132137
$verboseWarningMessage = $script:localizedData.TraceFlag_Remove_ShouldProcessVerboseWarning -f $InstanceName
133138
$captionMessage = $script:localizedData.TraceFlag_Remove_ShouldProcessCaption
134139

135140
if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
136141
{
137142
# Copy $PSBoundParameters to keep it intact.
138-
$setSqlDscTraceFlagParameters = @{} + $PSBoundParameters
143+
$setSqlDscTraceFlagParameters = Remove-CommonParameter -Hashtable $PSBoundParameters
139144

140-
$setSqlDscTraceFlagParameters.TraceFLag = $desiredTraceFlags
145+
$setSqlDscTraceFlagParameters.TraceFlag = $desiredTraceFlags
141146

142147
$originalErrorActionPreference = $ErrorActionPreference
143148

source/en-US/SqlServerDsc.strings.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ ConvertFrom-StringData @'
216216
# This string shall not end with full stop (.) since it is used as a title of ShouldProcess messages.
217217
TraceFlag_Remove_ShouldProcessCaption = Remove trace flag from instance
218218
TraceFlag_Remove_NoCurrentTraceFlags = There are no current trace flags on instance. Nothing to remove.
219+
TraceFlag_Remove_NoChange = The specified trace flags are not currently set on the instance. No changes needed.
219220
220221
## Get-SqlDscPreferredModule
221222
PreferredModule_ModuleVersionFound = Preferred module '{0}' with version '{1}' found.

tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BeforeDiscovery {
1919
}
2020
catch [System.IO.FileNotFoundException]
2121
{
22-
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
2323
}
2424
}
2525

tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BeforeDiscovery {
1919
}
2020
catch [System.IO.FileNotFoundException]
2121
{
22-
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
2323
}
2424
}
2525

tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BeforeDiscovery {
1919
}
2020
catch [System.IO.FileNotFoundException]
2121
{
22-
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
2323
}
2424
}
2525

tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BeforeDiscovery {
1919
}
2020
catch [System.IO.FileNotFoundException]
2121
{
22-
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
2323
}
2424
}
2525

0 commit comments

Comments
 (0)