Skip to content

Commit ef20ab5

Browse files
committed
(#3228) Update Pester Tests to validate .Net
This updates the .Net version Pester test to use the 64 bit registry as that is the one that Chocolatey CLI is using. Further, it updates the .Net version to be a low integer instead of deleting it. It's been found in some scenarios where the version is there but low .Net misbehaves. It also adds a retry onto taking ownership of the registry key as we've seen instances where it fails to take the ownership and so the test fails. This retry should hopefully resolve these sporadic failures.
1 parent eb95714 commit ef20ab5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/pester-tests/chocolatey.Tests.ps1

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,31 @@ exit $error.count
427427
# This is skipped when not run in CI because it modifies the local system.
428428
Context '.Net Registry is not set' -Skip:(-not $env:TEST_KITCHEN) {
429429
BeforeAll {
430-
$RegistryPath = 'SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full\'
431-
Set-RegistryKeyOwner -Key $RegistryPath
430+
$RegistryPath = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\'
431+
432+
# Sometimes this is failing. This allows it to try a second time before completely failing.
433+
try {
434+
Set-RegistryKeyOwner -Key $RegistryPath
435+
} catch {
436+
Write-Warning "Failed to set the registry key ownership. Attempting again."
437+
Set-RegistryKeyOwner -Key $RegistryPath
438+
}
439+
432440
$OriginalRelease = Get-ItemPropertyValue -Path "HKLM:\$RegistryPath" -Name Release
433-
Remove-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release
441+
Set-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release -Value 10
434442
$Output = Invoke-Choco help
435443
}
436444

437445
AfterAll {
438-
New-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release -Value $OriginalRelease
446+
Set-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release -Value $OriginalRelease
439447
}
440448

441449
It "Exits with Failure (1)" {
442450
$Output.ExitCode | Should -Be 1 -Because $Output.String
443451
}
444452

445453
It "Reports .NET Framework 4.8 is required" {
446-
$Output.Lines | Should -Contain '.NET 4.8 is not installed or may need a reboot to complete installation.'
454+
$Output.Lines | Should -Contain '.NET 4.8 is not installed or may need a reboot to complete installation.' -Because $Output.String
447455
}
448456
}
449457

0 commit comments

Comments
 (0)