Skip to content

Commit

Permalink
(chocolatey#23) Add tests to handle install all
Browse files Browse the repository at this point in the history
This commit adds some Pester tests to ensure that any attempts to run
the choco install all command is correctly handled when targeting
an alternative source.  This is simply asserting that there is an
error exit code, and that the correct output is displayed.

Some of the new tests are specifically set to only run on Test-Kitchen,
as there is the potential for changes to happen on the host machine,
and we don't want to impact people.
  • Loading branch information
gep13 committed May 30, 2024
1 parent d7a4018 commit 9205c4d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
30 changes: 30 additions & 0 deletions tests/pester-tests/features/CygwinSource.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Import-Module helpers/common-helpers

# This is skipped when not run in CI because it modifies the local system.
Describe "Cygwin Source" -Tag Chocolatey, CygwinSource -Skip:(-not $env:TEST_KITCHEN) {
BeforeAll {
Initialize-ChocolateyTestInstall
New-ChocolateyInstallSnapshot
Enable-ChocolateySource -Name hermes-setup
$null = Invoke-Choco install cygwin
}

AfterAll {
$null = Invoke-Choco uninstall cygwin --remove-dependencies
Remove-ChocolateyTestInstall
}

Context "install all" {
BeforeAll {
$Output = Invoke-Choco install all --source=cygwin
}

It 'Exits with exit code (1)' {
$Output.ExitCode | Should -Be 1 -Because $Output.String
}

It 'Outputs exception' {
$Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String
}
}
}
23 changes: 20 additions & 3 deletions tests/pester-tests/features/PythonSource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,29 @@ Describe "Python Source" -Tag Chocolatey, UpgradeCommand, PythonSource, ProxySki
}

It 'Exits with correct exit code (<ExitCode>)' {
$Output.ExitCode | Should -Be $ExitCode
$Output.ExitCode | Should -Be $ExitCode -Because $Output.String
}

It 'Outputs properly' {
$Output.Lines | Should -Not:($ExitCode -eq 0) -Contain "Alternative sources do not allow the use of the 'all' package name/keyword."
$Output.Lines | Should -Contain "Chocolatey upgraded $Count/$Count packages."
$Output.Lines | Should -Not:($ExitCode -eq 0) -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String
$Output.Lines | Should -Contain "Chocolatey upgraded $Count/$Count packages." -Because $Output.String
}
}

Context "install all" {
BeforeAll {
# For some reason under kitchen-pester we don't have pip on the path. This might be due to our snapshotting...
Import-Module $env:ChocolateyInstall/helpers/ChocolateyProfile.psm1
Update-SessionEnvironment
$Output = Invoke-Choco install all --source=python
}

It 'Exits with exit code (1)' {
$Output.ExitCode | Should -Be 1 -Because $Output.String
}

It 'Outputs exception' {
$Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String
}
}
}
30 changes: 30 additions & 0 deletions tests/pester-tests/features/RubySource.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Import-Module helpers/common-helpers

# This is skipped when not run in CI because it modifies the local system.
Describe "Ruby Source" -Tag Chocolatey, RubySource -Skip:(-not $env:TEST_KITCHEN) {
BeforeAll {
Initialize-ChocolateyTestInstall
New-ChocolateyInstallSnapshot
Enable-ChocolateySource -Name hermes-setup
$null = Invoke-Choco install ruby.portable
}

AfterAll {
$null = Invoke-Choco uninstall ruby.portable --remove-dependencies
Remove-ChocolateyTestInstall
}

Context "install all" {
BeforeAll {
$Output = Invoke-Choco install all --source=ruby
}

It 'Exits with exit code (1)' {
$Output.ExitCode | Should -Be 1 -Because $Output.String
}

It 'Outputs exception' {
$Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String
}
}
}
26 changes: 26 additions & 0 deletions tests/pester-tests/features/WindowsFeaturesSource.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Import-Module helpers/common-helpers

Describe "Windows Features Source" -Tag Chocolatey, WindowsFeaturesSource {
BeforeAll {
Initialize-ChocolateyTestInstall
New-ChocolateyInstallSnapshot
}

AfterAll {
Remove-ChocolateyTestInstall
}

Context "install all" {
BeforeAll {
$Output = Invoke-Choco install all --source=windowsfeatures
}

It 'Exits with exit code (1)' {
$Output.ExitCode | Should -Be 1 -Because $Output.String
}

It 'Outputs exception' {
$Output.Lines | Should -Contain "Alternative sources do not allow the use of the 'all' package name/keyword." -Because $Output.String
}
}
}

0 comments on commit 9205c4d

Please sign in to comment.