Skip to content

Commit

Permalink
(chocolatey#1761) 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
enable/disable a feature that is already in the desired state, 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 24, 2024
1 parent 8036dcb commit dd50700
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/pester-tests/commands/choco-feature.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,76 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, FeatureCommand {
}
}

Context "Enabling a feature when it is already enabled" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

# Ensure that the feature is already enabled
$null = Invoke-Choco feature enable --name allowGlobalConfirmation

$Output = Invoke-Choco feature enable --name allowGlobalConfirmation
}

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 feature enable --name allowGlobalConfirmation
}

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."
}
}
}

Context "Disabling a feature when it is already disabled" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

# Ensure that the feature is already disabled
$null = Invoke-Choco feature disable --name allowGlobalConfirmation

$Output = Invoke-Choco feature disable --name allowGlobalConfirmation
}

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 feature disable --name allowGlobalConfirmation
}

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."
}
}
}

Context "Disabling usePackageRepositoryOptimizations" {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Expand Down

0 comments on commit dd50700

Please sign in to comment.