Skip to content

Commit e0f893e

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 adds a test for 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 f4d8cc2 commit e0f893e

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

tests/pester-tests/chocolatey.Tests.ps1

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,18 @@ exit $error.count
425425
}
426426

427427
# This is skipped when not run in CI because it modifies the local system.
428-
Context '.Net Registry is not set' -Skip:(-not $env:TEST_KITCHEN) {
428+
Context '.Net Registry is not present' -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
433441
Remove-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release
434442
$Output = Invoke-Choco help
@@ -443,11 +451,43 @@ exit $error.count
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

450458

459+
# This is skipped when not run in CI because it modifies the local system.
460+
Context '.Net Registry is not valid' -Skip:(-not $env:TEST_KITCHEN) {
461+
BeforeAll {
462+
$RegistryPath = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\'
463+
464+
# Sometimes this is failing. This allows it to try a second time before completely failing.
465+
try {
466+
Set-RegistryKeyOwner -Key $RegistryPath
467+
} catch {
468+
Write-Warning "Failed to set the registry key ownership. Attempting again."
469+
Set-RegistryKeyOwner -Key $RegistryPath
470+
}
471+
472+
$OriginalRelease = Get-ItemPropertyValue -Path "HKLM:\$RegistryPath" -Name Release
473+
Set-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release -Value 10
474+
$Output = Invoke-Choco help
475+
}
476+
477+
AfterAll {
478+
Set-ItemProperty -Path "HKLM:\$RegistryPath" -Name Release -Value $OriginalRelease
479+
}
480+
481+
It "Exits with Failure (1)" {
482+
$Output.ExitCode | Should -Be 1 -Because $Output.String
483+
}
484+
485+
It "Reports container registration failed" {
486+
$Output.Lines | Should -Contain 'Container registration encountered an irrecoverable error.' -Because $Output.String
487+
$Output.Lines | Should -Contain 'It could be that .NET 4.8 may be corrupted, or may be a really old version.' -Because $Output.String
488+
}
489+
}
490+
451491
Context 'Chocolatey lib directory missing' {
452492
BeforeAll {
453493
New-ChocolateyInstallSnapshot

0 commit comments

Comments
 (0)