From 3644778db061eb2ed003293aefe6886faf172a71 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Thu, 23 May 2024 01:10:21 -0700 Subject: [PATCH] (#1759) Add test for new enhanced exit code 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. --- .../commands/choco-apikey.Tests.ps1 | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/pester-tests/commands/choco-apikey.Tests.ps1 b/tests/pester-tests/commands/choco-apikey.Tests.ps1 index 5ed9daf81f..9660a61c30 100644 --- a/tests/pester-tests/commands/choco-apikey.Tests.ps1 +++ b/tests/pester-tests/commands/choco-apikey.Tests.ps1 @@ -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 }