Skip to content

Commit 6aabed6

Browse files
authored
xCluster: Fixed random problem with tests failing (dsccommunity#134)
- Changes to xCluster - Fixed random problem with tests failing with error "Invalid token for impersonation - it cannot be duplicated." (issue dsccommunity#133).
1 parent adaa7ac commit 6aabed6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
etc.
3636
- Enabled localization for all strings ([issue #83](https://github.com/PowerShell/xFailOverCluster/issues/83)).
3737
- Added tests to improve code coverage.
38+
- Fixed random problem with tests failing with error "Invalid token for
39+
impersonation - it cannot be duplicated." ([issue #133](https://github.com/PowerShell/xFailOverCluster/issues/133)).
3840
- Changes to xWaitForCluster
3941
- Refactored the unit test for this resource to use stubs and increase coverage
4042
([issue #78](https://github.com/PowerShell/xFailOverCluster/issues/78)).

Tests/Unit/MSFT_xCluster.Tests.ps1

+31
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ try
104104
)
105105
}
106106

107+
$mockNewObjectWindowsIdentity = {
108+
return [PSCustomObject] @{} |
109+
Add-Member -MemberType ScriptMethod -Name Impersonate -Value {
110+
return [PSCustomObject] @{} |
111+
Add-Member -MemberType ScriptMethod -Name Undo -Value {} -PassThru |
112+
Add-Member -MemberType ScriptMethod -Name Dispose -Value {} -PassThru -Force
113+
} -PassThru -Force
114+
}
115+
116+
$mockNewObjectWindowsIdentity_ParameterFilter = {
117+
$TypeName -eq 'Security.Principal.WindowsIdentity'
118+
}
119+
107120
$mockDefaultParameters = @{
108121
Name = $mockClusterName
109122
StaticIPAddress = $mockStaticIpAddress
@@ -140,6 +153,8 @@ try
140153
Mock -CommandName Add-Type -MockWith {
141154
return $mockLibImpersonationObject
142155
}
156+
157+
Mock -CommandName New-Object -MockWith $mockNewObjectWindowsIdentity -ParameterFilter $mockNewObjectWindowsIdentity_ParameterFilter -Verifiable
143158
}
144159

145160
Context 'When the computers domain name cannot be evaluated' {
@@ -194,6 +209,14 @@ try
194209
}
195210

196211
Describe 'xCluster\Set-TargetResource' {
212+
BeforeAll {
213+
Mock -CommandName Add-Type -MockWith {
214+
return $mockLibImpersonationObject
215+
}
216+
217+
Mock -CommandName New-Object -MockWith $mockNewObjectWindowsIdentity -ParameterFilter $mockNewObjectWindowsIdentity_ParameterFilter -Verifiable
218+
}
219+
197220
Context 'When computers domain name cannot be evaluated' {
198221
It 'Should throw the correct error message' {
199222
$mockDynamicDomainName = $null
@@ -339,6 +362,14 @@ try
339362
}
340363

341364
Describe 'xCluster\Test-TargetResource' {
365+
BeforeAll {
366+
Mock -CommandName Add-Type -MockWith {
367+
return $mockLibImpersonationObject
368+
}
369+
370+
Mock -CommandName New-Object -MockWith $mockNewObjectWindowsIdentity -ParameterFilter $mockNewObjectWindowsIdentity_ParameterFilter -Verifiable
371+
}
372+
342373
Context 'When computers domain name cannot be evaluated' {
343374
It 'Should throw the correct error message' {
344375
$mockDynamicDomainName = $null

0 commit comments

Comments
 (0)