Skip to content

Commit

Permalink
(chocolatey#1762) Add test for new enhanced exit code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gep13 committed May 28, 2024
1 parent 6cbdb82 commit 4fc4bb2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/pester-tests/commands/choco-pin.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 4fc4bb2

Please sign in to comment.