From 4fc4bb231142b7a11e02b070367e2e90f041c7da Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Wed, 22 May 2024 08:10:21 -0700 Subject: [PATCH] (#1762) Add test for new enhanced exit code Now, when you have useEnhancedExitCodes turned on, if you try to set a pin on a package, that is already set, the exit code will change to be a 2, giving a clear indication that no action was taken. This commit adds a Pester test to verify that this works as expected. --- .../pester-tests/commands/choco-pin.Tests.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/pester-tests/commands/choco-pin.Tests.ps1 b/tests/pester-tests/commands/choco-pin.Tests.ps1 index 465b434cf7..7e8f0e0725 100644 --- a/tests/pester-tests/commands/choco-pin.Tests.ps1 +++ b/tests/pester-tests/commands/choco-pin.Tests.ps1 @@ -112,6 +112,24 @@ Describe "choco pin" -Tag Chocolatey, PinCommand { $Output.Lines | Should -Contain "Nothing to change. Pin already set or removed." $CurrentPins | Should -Contain "upgradepackage|1.0.0$listSuffix" } + + Context "when using enhanced exit codes" { + BeforeAll { + $null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes" + + $Output = Invoke-Choco pin add --name upgradepackage + $CurrentPins = Invoke-Choco pin list --LimitOutput | ForEach-Object Lines + } + + It "Exits with ExitCode 2" { + $Output.ExitCode | Should -Be 2 -Because $Output.String + } + + It "Changes Nothing" { + $Output.Lines | Should -Contain "Nothing to change. Pin already set or removed." + $CurrentPins | Should -Contain "upgradepackage|1.0.0$listSuffix" + } + } } Context "Setting a Pin for a non-installed Package" {