Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
Comment thread
johlju marked this conversation as resolved.
}
}
}
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
Comment thread
johlju marked this conversation as resolved.
}
}
}
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