Skip to content

Commit

Permalink
(chocolatey#1759) 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
add an apikey when it is already added 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 authored and corbob committed May 27, 2024
1 parent 655a509 commit 3644778
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/pester-tests/commands/choco-apikey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,41 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, ApiKeyCommand {
}
}

Context "Adding an apikey when it is already added" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

# Ensure that the apikey is indeed set
$null = Invoke-Choco apikey add --source "https://somewhere.out/there/" --api-key "123-4567-89"

$Output = Invoke-Choco apikey add --source "https://somewhere.out/there/" --api-key "123-4567-89"
}

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

It "Changes Nothing" {
$Output.Lines | Should -Contain "Nothing to change. Config already set."
}

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

$Output = Invoke-Choco apikey add --source "https://somewhere.out/there/" --api-key "123-4567-89"
}

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

It "Changes Nothing" {
$Output.Lines | Should -Contain "Nothing to change. Config already set."
}
}
}

# This needs to be the last test in this block, to ensure NuGet configurations aren't being created.
Test-NuGetPaths
}

0 comments on commit 3644778

Please sign in to comment.