diff --git a/CHANGELOG.md b/CHANGELOG.md index b1c5e898..4f6336b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 792fc0b0..67843b83 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -9,7 +9,10 @@ InvokeBuild = 'latest' PSScriptAnalyzer = 'latest' - Pester = 'latest' + Pester = @{ + Version = '6.0.0-rc2' + Parameters = @{ AllowPrerelease = $true } + } Plaster = 'latest' ModuleBuilder = 'latest' ChangelogManagement = 'latest' diff --git a/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 b/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 index 4baf3e5f..9ae46bdc 100644 --- a/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 +++ b/tests/Integration/ComputerManagementDsc.Common.Tests.ps1 @@ -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' } diff --git a/tests/Unit/DSC_Computer.Tests.ps1 b/tests/Unit/DSC_Computer.Tests.ps1 index 0b5ca585..3cc84f4b 100644 --- a/tests/Unit/DSC_Computer.Tests.ps1 +++ b/tests/Unit/DSC_Computer.Tests.ps1 @@ -676,7 +676,7 @@ Describe 'DSC_Computer\Test-TargetResource' { } } - BeforeEach { + BeforeDiscovery { $testCases = @( @{ Name = $env:COMPUTERNAME } @{ Name = 'localhost' } diff --git a/tests/Unit/DSC_SystemProtection.Tests.ps1 b/tests/Unit/DSC_SystemProtection.Tests.ps1 index 862f784c..0f2765af 100644 --- a/tests/Unit/DSC_SystemProtection.Tests.ps1 +++ b/tests/Unit/DSC_SystemProtection.Tests.ps1 @@ -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 } } } @@ -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 } } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } diff --git a/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 b/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 index ecdf06fc..bdb36a1d 100644 --- a/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 +++ b/tests/Unit/DSC_SystemRestorePoint.Tests.ps1 @@ -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 } } } @@ -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 } } }