Skip to content

Commit

Permalink
(chocolatey#2200) 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
upgrade a package, whether directly, or via the all keyword, and there
are no upgrade available, 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 68c352e commit 1cc939c
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/pester-tests/commands/choco-upgrade.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,77 @@
}
}

Context "Attempt to upgrade a package when there isn't an upgrade available" -Tag Internal {
BeforeAll {
Restore-ChocolateyInstallSnapshot

Enable-ChocolateySource -Name hermes-setup
$null = Invoke-Choco install wget

$Output = Invoke-Choco upgrade wget
}

It 'Exits with Success (0)' {
$Output.ExitCode | Should -Be 0 -Because $Output.String
}

It 'Displays that upgrade was attempted but wasnt required' {
$Output.Lines | Should -Contain "Chocolatey upgraded 0/1 packages." -Because $Output.String
}

Context "when using enhanced exit codes" {
BeforeAll {
$null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes"

$Output = Invoke-Choco upgrade wget
}

It "Exits with ExitCode 2" {
$Output.ExitCode | Should -Be 2 -Because $Output.String
}

It 'Displays that upgrade was attempted but wasnt required' {
$Output.Lines | Should -Contain "Chocolatey upgraded 0/1 packages." -Because $Output.String
}
}
}

Context "Attempt to run upgrade all when there isn't any upgrade available" -Tag Internal {
BeforeAll {
Restore-ChocolateyInstallSnapshot

Enable-ChocolateySource -Name hermes-setup
$null = Invoke-Choco install wget
$null = Invoke-Choco install curl

$Output = Invoke-Choco upgrade all
}

It 'Exits with Success (0)' {
$Output.ExitCode | Should -Be 0 -Because $Output.String
}

It 'Displays that upgrade was attempted but wasnt required' {
$Output.Lines | Should -Contain "Chocolatey upgraded 0/2 packages." -Because $Output.String
}

Context "when using enhanced exit codes" {
BeforeAll {
$null = Enable-ChocolateyFeature -Name "useEnhancedExitCodes"

$Output = Invoke-Choco upgrade all
}

It "Exits with ExitCode 2" {
$Output.ExitCode | Should -Be 2 -Because $Output.String
}

It 'Displays that upgrade was attempted but wasnt required' {
$Output.Lines | Should -Contain "Chocolatey upgraded 0/2 packages." -Because $Output.String
}
}
}

# We exclude this test when running CCM, as it will install and remove
# the firefox package which is used through other tests that will be affected.
Context "Upgrading packages while remembering arguments with multiple packages using arguments" -Tag CCMExcluded, Internal, VMOnly {
Expand Down

0 comments on commit 1cc939c

Please sign in to comment.