Skip to content

Commit

Permalink
(chocolatey#72) Add Pester tests to cover new functionality
Browse files Browse the repository at this point in the history
In these release, it is now possible to include already configured
sources, i.e. in the chocolatey.config file, using an option on the
info, install, outdated, search, and upgrade commands.

This commit adds tests to cover these being included.
  • Loading branch information
gep13 committed May 30, 2024
1 parent a9e1685 commit b28de4f
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/pester-tests/commands/choco-info.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@
}
}

Context "Should include configured sources" {
BeforeAll {
Remove-NuGetPaths
Initialize-ChocolateyTestInstall -Source $PSScriptRoot\testpackages
Invoke-Choco install installpackage --confirm

$Output = Invoke-Choco info installpackage --include-configured-sources --debug
}

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

It "Should mention that configured sources have been included" {
$Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String
}
}

Context "Listing package information when package can be found" {
BeforeDiscovery {
$infoItems = @(
Expand Down
70 changes: 70 additions & 0 deletions tests/pester-tests/commands/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,76 @@
}
}

Context "Installing a Package (Happy Path) including configured sources" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$PackageUnderTest = "installpackage"

$Output = Invoke-Choco install $PackageUnderTest --include-configured-sources --debug --confirm
}

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

It "Installed a package to the lib directory" {
"$env:ChocolateyInstall\lib\$PackageUnderTest" | Should -Exist
}

# We are skipping this for now, until we have stabilized the directory
# path reporting functionality. There are times that this test will
# fail due to Chocolatey not reporting the path.
# This failure seems to happen randomly, and is therefore not a
# reliable test we can make.
It "Outputs the installation directory (which should exist)" -Skip {
$directoryPath = "$env:ChocolateyInstall\lib\$PackageUnderTest"
$lineRegex = [regex]::Escape($directoryPath)

$foundPath = $Output.Lines -match $lineRegex
$foundPath | Should -Not -BeNullOrEmpty
$foundPath | Should -Exist
}

It "Installs the expected version of the package" {
"$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec" | Should -Exist
[xml]$XML = Get-Content "$env:ChocolateyInstall\lib\$PackageUnderTest\$PackageUnderTest.nuspec"
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Creates a Console Shim in the Bin Directory" {
"$env:ChocolateyInstall\bin\console.exe" | Should -Exist
}

It "Creates a Graphical Shim in the Bin Directory" {
"$env:ChocolateyInstall\bin\graphical.exe" | Should -Exist
}

It "Does not create a Shim for Ignored Executable in the Bin Directory" {
"$env:ChocolateyInstall\bin\not.installed.exe" | Should -Not -Exist
}

It "Does not create a Shim for Ignored Executable (with mismatched case) in the Bin Directory" {
"$env:ChocolateyInstall\bin\casemismatch.exe" | Should -Not -Exist
}

It "Does not create an extensions folder for the package" {
"$env:ChocolateyInstall\extensions\$PackageUnderTest" | Should -Not -Exist
}

It "Contains the output of the ChocolateyInstall.ps1 script" {
$Output.Lines | Should -Contain "Ya!"
}

It "Outputs a message showing that installation was successful" {
$Output.String | Should -Match "Chocolatey installed 1/1 packages\."
}

It "Should mention that configured sources have been included" {
$Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String
}
}

Context "Installing a Package with Packages.config" {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Expand Down
14 changes: 14 additions & 0 deletions tests/pester-tests/commands/choco-outdated.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ Describe "choco outdated" -Tag Chocolatey, OutdatedCommand {
Remove-ChocolateyTestInstall
}

Context "Should include configured sources" {
BeforeAll {
$Output = Invoke-Choco outdated --include-configured-sources --debug
}

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

It "Should mention that configured sources have been included" {
$Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String
}
}

Context "outdated ignore-pinned uses correct enhanced exit codes" -ForEach @(
@{ Argument = '' ; ExitCode = 2 }
@{ Argument = '--ignore-pinned' ; ExitCode = 0 }
Expand Down
14 changes: 14 additions & 0 deletions tests/pester-tests/commands/choco-search.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, SearchCommand, FindComma
}
}

Context "Should include configured sources" {
BeforeAll {
$Output = Invoke-Choco $_ upgradepackage --include-configured-sources --debug
}

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

It "Should mention that configured sources have been included" {
$Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String
}
}

Context "Searching for a particular package" {
BeforeAll {
$Output = Invoke-Choco $_ upgradepackage
Expand Down
19 changes: 19 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,25 @@
}
}

Context "Should include configured sources" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

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

$Output = Invoke-Choco upgrade wget --include-configured-sources --debug
}

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

It "Should mention that configured sources have been included" {
$Output.Lines | Should -Contain "Including sources from chocolatey.config file." -Because $Output.String
}
}

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

0 comments on commit b28de4f

Please sign in to comment.