Skip to content
Draft
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

### Changed

- `ActiveDirectoryDsc`
- Updated unit tests for Pester 6 compatibility - forward unmatched `Test-Path`
mock calls to the real cmdlet, suppress unmatched `Write-Verbose` calls, and
replace the removed `Assert-VerifiableMock` with `Should -InvokeVerifiable`.

## [6.7.1] - 2025-12-05

### Added
Expand Down
5 changes: 4 additions & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
Pester = @{
Version = '6.0.0-rc4'
Parameters = @{ AllowPrerelease = $true }
}
Plaster = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ Describe 'ActiveDirectoryDsc.Common\Restore-ADCommonObject' {
}

It 'Should call Get-ADObject as well as Restore-ADObject' {
Assert-VerifiableMock
Should -InvokeVerifiable
}

It 'Should throw an InvalidOperationException when object parent does not exist' {
Expand Down Expand Up @@ -1558,7 +1558,7 @@ Describe 'ActiveDirectoryDsc.Common\Get-ADDirectoryContext' {
}
}

Assert-VerifiableMock
Should -InvokeVerifiable
}
}

Expand Down Expand Up @@ -1625,7 +1625,7 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr
}
}

Assert-VerifiableMock
Should -InvokeVerifiable
}

Context 'When no domain controller is found' {
Expand All @@ -1647,6 +1647,9 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr
)
}

# Pester v6 throws instead of calling the real command when no -ParameterFilter
# matches. Suppress unmatched Write-Verbose calls (v5 let them through).
Mock -CommandName Write-Verbose -MockWith { }
Mock -CommandName Write-Verbose -ParameterFilter {
$Message -like 'Searching for a domain controller*'
} -MockWith {
Expand All @@ -1658,10 +1661,12 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr
{ Find-DomainController -DomainName $mockDomainName } | Should -Not -Throw

Should -Invoke -CommandName Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
Should -Invoke -CommandName Write-Verbose -Exactly -Times 1 -Scope It
Should -Invoke -CommandName Write-Verbose -ParameterFilter {
$Message -like 'Searching for a domain controller*'
} -Exactly -Times 1 -Scope It
}

Assert-VerifiableMock
Should -InvokeVerifiable
}

Context 'When the lookup for a domain controller fails' {
Expand All @@ -1686,7 +1691,7 @@ Describe 'ActiveDirectoryDsc.Common\Find-DomainController' -Tag 'FindDomainContr
Should -Invoke -CommandName Find-DomainControllerFindOneWrapper -Exactly -Times 1 -Scope It
}

Assert-VerifiableMock
Should -InvokeVerifiable
}

Context 'When the Find-DomainController throws an authentication exception' {
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/MSFT_ADDomain.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ AfterAll {
Describe 'MSFT_ADDomain\Get-TargetResource' -Tag 'Get' {
BeforeAll {
Mock -CommandName Assert-Module
# Pester v6 throws instead of calling the real command when no -ParameterFilter
# matches. Forward unmatched Test-Path calls to the real cmdlet to keep v5 behaviour.
Mock -CommandName Test-Path -MockWith { & (Get-Command -Name 'Test-Path' -CommandType Cmdlet) @PesterBoundParameters }
Mock -CommandName Test-Path -ParameterFilter {
$Path -eq 'C:\Windows\SysVol\contoso.com'
} -MockWith { $true }
Expand Down Expand Up @@ -675,6 +678,9 @@ Describe 'MSFT_ADDomain\Set-TargetResource' -Tag 'Set' {
Context 'When the domain controller is pending reboot and SuppressReboot is $false' {
BeforeAll {
# Make the resource think a reboot is pending after installation.
# Pester v6 throws instead of calling the real command when no -ParameterFilter
# matches. Forward unmatched Test-Path calls to the real cmdlet to keep v5 behaviour.
Mock -CommandName Test-Path -MockWith { & (Get-Command -Name 'Test-Path' -CommandType Cmdlet) @PesterBoundParameters }
Mock -CommandName Test-Path -ParameterFilter {
$Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\LocatorDCPromoPreRebootHint'
} -MockWith { $true }
Expand Down Expand Up @@ -1078,6 +1084,9 @@ Describe 'MSFT_ADDomain\Set-TargetResource' -Tag 'Set' {

Context 'When the domain controller is pending reboot and SuppressReboot is $false' {
BeforeAll {
# Pester v6 throws instead of calling the real command when no -ParameterFilter
# matches. Forward unmatched Test-Path calls to the real cmdlet to keep v5 behaviour.
Mock -CommandName Test-Path -MockWith { & (Get-Command -Name 'Test-Path' -CommandType Cmdlet) @PesterBoundParameters }
Mock -CommandName Test-Path -ParameterFilter {
$Path -eq 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\LocatorDCPromoPreRebootHint'
} -MockWith { $true }
Expand Down
7 changes: 6 additions & 1 deletion tests/Unit/MSFT_WaitForADDomain.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ Describe 'MSFT_WaitForADDomain\Get-TargetResource' -Tag 'Get' {

Context 'When using BuiltInCredential parameter' {
BeforeAll {
# Pester v6 throws instead of calling the real command when no -ParameterFilter
# matches. Suppress unmatched Write-Verbose calls (v5 let them through).
Mock -CommandName Write-Verbose -MockWith { }
Mock -CommandName Write-Verbose -ParameterFilter {
$Message -like 'Impersonating the credentials ''BuiltInCredential''*'
} -MockWith {
Expand Down Expand Up @@ -185,7 +188,9 @@ Describe 'MSFT_WaitForADDomain\Get-TargetResource' -Tag 'Get' {
$result.Credential | Should -BeNullOrEmpty
}

Should -Invoke -CommandName Write-Verbose -Exactly -Times 1 -Scope It
Should -Invoke -CommandName Write-Verbose -ParameterFilter {
$Message -like 'Impersonating the credentials ''BuiltInCredential''*'
} -Exactly -Times 1 -Scope It
}
}
}
Expand Down
Loading