Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- `ComputerManagementDsc`
- Updated unit tests for Pester 6 compatibility - replaced the removed
`Assert-MockCalled` with `Should -Invoke`, and moved a data-driven test's
`$testCases` into `BeforeDiscovery` so `-ForEach` is populated at discovery
time (Pester 6 throws on a `$null`/empty `-ForEach`).
- `azure-pipelines.yml`
- Remove `windows-2019` images fixes [#451](https://github.com/dsccommunity/ComputerManagementDsc/issues/451).
- Module manifest: Set `CmdletsToExport` to `'*'` to satisfy HQRM tests.
Expand Down
4 changes: 3 additions & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
Pester = @{
Version = '6.0.0'
}
Plaster = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Expand Down
6 changes: 6 additions & 0 deletions tests/Integration/ComputerManagementDsc.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ Describe 'ComputerManagementDsc.Common\Set-TimeZoneId' {
#>
Context '''Set-TimeZone'' is not available but ''Add-Type'' is available' {
BeforeAll {
# Pester v6 throws instead of calling the real command when a mock has only
# -ParameterFilter behaviours and none match. Forward unmatched Get-Command
# calls (e.g. the 'Get-TimeZone' lookup in Get-TimeZoneId) to the real cmdlet
# to keep the v5 fall-through behaviour.
Mock -CommandName Get-Command -MockWith { & (Get-Command -Name 'Get-Command' -CommandType Cmdlet) @PesterBoundParameters }

Mock -CommandName Get-Command -ParameterFilter {
$Name -eq 'Add-Type'
} -MockWith { 'Add-Type' }
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/DSC_Computer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ Describe 'DSC_Computer\Test-TargetResource' {
}
}

BeforeEach {
BeforeDiscovery {
$testCases = @(
@{ Name = $env:COMPUTERNAME }
@{ Name = 'localhost' }
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/DSC_SystemProtection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Describe "DSC_SystemProtection\Get-TargetResource" -Tag 'Get' {
$protectionSettings = Get-TargetResource -Ensure 'Present' -DriveLetter 'C'

$protectionSettings.Ensure | Should -Be 'Absent'
Assert-MockCalled -CommandName Write-Warning -Times 1
Should -Invoke -CommandName Write-Warning -Times 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚑ Quick win

Add -Exactly and -Scope It to all Should -Invoke assertions.

Per the test guidelines, call-count assertions must use Should -Invoke -Exactly -Times <n> -Scope It. All migrated Should -Invoke calls in this file are missing both -Exactly and -Scope It. Without -Exactly, -Times 1 asserts "at least 1" rather than "exactly 1". Without -Scope It, mock calls may be counted across the entire Context or Describe instead of just the current It block β€” particularly impactful in Context 'When configuration is required' (line 351) which contains multiple It blocks. This is also inconsistent with the already-migrated Should -Invoke calls in DSC_Computer.Tests.ps1 (e.g., lines 789–790) which use -Exactly -Times 0 -Scope It.

As per coding guidelines, use Should -Invoke -Exactly -Times <n> -Scope It for call-count assertions, and assert <n> calls inside the It block; do not assert call counts across an entire Describe or Context.

πŸ›‘οΈ Proposed fix for all changed `Should -Invoke` calls
 # Line 138
-                    Should -Invoke -CommandName Write-Warning -Times 1
+                    Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It

 # Line 266
-                Should -Invoke -CommandName Write-Warning -Times 2
+                Should -Invoke -CommandName Write-Warning -Exactly -Times 2 -Scope It

 # Line 360
-                    Should -Invoke -CommandName Enable-ComputerRestore -Times 1
+                    Should -Invoke -CommandName Enable-ComputerRestore -Exactly -Times 1 -Scope It

 # Line 372
-                    Should -Invoke -CommandName Disable-ComputerRestore
+                    Should -Invoke -CommandName Disable-ComputerRestore -Exactly -Times 1 -Scope It

 # Lines 385-386
-                    Should -Invoke -CommandName Enable-ComputerRestore -Times 1
-                    Should -Invoke -CommandName Invoke-VssAdmin -Times 1
+                    Should -Invoke -CommandName Enable-ComputerRestore -Exactly -Times 1 -Scope It
+                    Should -Invoke -CommandName Invoke-VssAdmin -Exactly -Times 1 -Scope It

 # Lines 428-431
-                    Should -Invoke -CommandName Enable-ComputerRestore -Times 1
-                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Times 2
-                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Times 1
-                    Should -Invoke -CommandName Write-Warning -Times 1
+                    Should -Invoke -CommandName Enable-ComputerRestore -Exactly -Times 1 -Scope It
+                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Exactly -Times 2 -Scope It
+                    Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Exactly -Times 1 -Scope It
+                    Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It

Also applies to: 266-266, 360-360, 372-372, 385-386, 428-431

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/DSC_SystemProtection.Tests.ps1` at line 138, Update all migrated
call-count assertions in DSC_SystemProtection.Tests.ps1 to use Should -Invoke
-Exactly -Times <n> -Scope It. The affected assertions in the current test block
and the other listed locations should be changed to assert per-It counts only,
matching the existing pattern used in DSC_Computer.Tests.ps1. Use the Should
-Invoke calls in this file to locate and update each assertion so mock counts
are not aggregated across a Context or Describe.

Source: Coding guidelines

}
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ Describe "DSC_SystemProtection\Test-TargetResource" -Tag 'Test' {
$desiredState = Test-TargetResource -Ensure 'Present' -DriveLetter 'C'

$desiredState | Should -BeTrue
Assert-MockCalled -CommandName Write-Warning -Times 2
Should -Invoke -CommandName Write-Warning -Times 2
}
}
}
Expand Down Expand Up @@ -357,7 +357,7 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' {

Set-TargetResource -Ensure 'Present' -DriveLetter 'P'

Assert-MockCalled -CommandName Enable-ComputerRestore -Times 1
Should -Invoke -CommandName Enable-ComputerRestore -Times 1
}
}

Expand All @@ -369,7 +369,7 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' {

Set-TargetResource -Ensure 'Absent' -DriveLetter 'P'

Assert-MockCalled -CommandName Disable-ComputerRestore
Should -Invoke -CommandName Disable-ComputerRestore
}
}

Expand All @@ -382,8 +382,8 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' {

Set-TargetResource -Ensure 'Present' -DriveLetter 'P' -DiskUsage 20

Assert-MockCalled -CommandName Enable-ComputerRestore -Times 1
Assert-MockCalled -CommandName Invoke-VssAdmin -Times 1
Should -Invoke -CommandName Enable-ComputerRestore -Times 1
Should -Invoke -CommandName Invoke-VssAdmin -Times 1
}
}

Expand Down Expand Up @@ -425,10 +425,10 @@ Describe "DSC_SystemProtection\Set-TargetResource" -Tag 'Set' {

Set-TargetResource -Ensure 'Present' -DriveLetter 'P' -DiskUsage 1 -Force $true

Assert-MockCalled -CommandName Enable-ComputerRestore -Times 1
Assert-MockCalled -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Times 2
Assert-MockCalled -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Times 1
Assert-MockCalled -CommandName Write-Warning -Times 1
Should -Invoke -CommandName Enable-ComputerRestore -Times 1
Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Resize' } -Times 2
Should -Invoke -CommandName Invoke-VssAdmin -ParameterFilter { $Operation -eq 'Delete' } -Times 1
Should -Invoke -CommandName Write-Warning -Times 1
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/DSC_SystemRestorePoint.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Describe "DSC_SystemRestorePoint\Get-TargetResource" -Tag 'Get' {
$protectionSettings = Get-TargetResource -Ensure 'Present' -Description 'DSC Unit Test'

$protectionSettings.Ensure | Should -Be 'Absent'
Assert-MockCalled -CommandName Write-Warning -Times 1
Should -Invoke -CommandName Write-Warning -Times 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚑ Quick win

Add -Exactly and -Scope It to all Should -Invoke assertions.

Same issue as DSC_SystemProtection.Tests.ps1: both migrated Should -Invoke calls are missing -Exactly and -Scope It as required by the test guidelines. Without -Exactly, -Times 1 asserts "at least 1" rather than "exactly 1". Without -Scope It, mock calls may be counted across the entire Context instead of just the current It block.

As per coding guidelines, use Should -Invoke -Exactly -Times <n> -Scope It for call-count assertions.

πŸ›‘οΈ Proposed fix for all changed `Should -Invoke` calls
 # Line 116
-                Should -Invoke -CommandName Write-Warning -Times 1
+                Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It

 # Line 204
-                Should -Invoke -CommandName Write-Warning -Times 2
+                Should -Invoke -CommandName Write-Warning -Exactly -Times 2 -Scope It

Also applies to: 204-204

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/DSC_SystemRestorePoint.Tests.ps1` at line 116, The migrated Should
-Invoke assertions in DSC_SystemRestorePoint.Tests.ps1 are missing the required
call-count qualifiers. Update the affected test assertions to use Should -Invoke
with -Exactly and -Scope It alongside -Times 1 so the mock verification is
scoped to the current It block and checks for an exact invocation count. Apply
this to both migrated Write-Warning assertions in the test file, matching the
pattern already used in DSC_SystemProtection.Tests.ps1.

Source: Coding guidelines

}
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@ Describe "DSC_SystemRestorePoint\Test-TargetResource" -Tag 'Test' {
$desiredState = Test-TargetResource -Ensure 'Present' -Description 'DSC Unit Test'

$desiredState | Should -BeTrue
Assert-MockCalled -CommandName Write-Warning -Times 2
Should -Invoke -CommandName Write-Warning -Times 2
}
}
}
Expand Down