Skip to content

Commit

Permalink
(chocolatey#798) Add tests for pinning package on install
Browse files Browse the repository at this point in the history
Add tests that we are pinning packages when during upgrade and install
when done with the `--pin` parameter.
  • Loading branch information
corbob committed Sep 26, 2022
1 parent 8c1e1b0 commit 37c942c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/chocolatey-tests/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,37 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
}
}

Context "Install '<Package>' package with (<Command>) specified" -ForEach @(
@{ Command = '--pin' ; Package = 'installpackage' ; Contains = $true }
@{ Command = '' ; Package = 'installpackage' ; Contains = $false }
@{ Command = '' ; Package = 'packages.config' ; Contains = $true }
) {
BeforeAll {
Restore-ChocolateyInstallSnapshot

if ($Package -eq 'packages.config') {
@"
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="installpackage" pinPackage="true" />
</packages>
"@ | Set-Content $PWD/packages.config
}

$null = Invoke-Choco install $Package $Command --confirm
$Output = Invoke-Choco pin list
}

It "Output should include pinned package" {
if ($Contains) {
$Output.String | Should -Match "installpackage|1.0.0"
}
else {
$Output.String | Should -Not -Match "installpackage|1.0.0"
}
}
}

Context "Installing package that extracts local zip archive while disabling logging" {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Expand Down
27 changes: 27 additions & 0 deletions tests/chocolatey-tests/choco-upgrade.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand {
}
}

Context "Upgrade package with (<Command>) specified" -ForEach @(
@{ Command = '--pin' ; Contains = $true }
@{ Command = '' ; Contains = $false }
) {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$Package = 'upgradepackage'
$null = Invoke-Choco install $Package --version 1.0.0 --confirm
$null = Invoke-Choco upgrade $Package $Command --confirm
$Output = Invoke-Choco pin list
}

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

It "Output should include pinned package" {
if ($Contains) {
$Output.String | Should -Match "$Package|1.1.0"
}
else {
$Output.String | Should -Not -Match "$Package|1.1.0"
}
}
}

Context "Upgrading packages while remembering arguments with only one package using arguments" -Tag Internal {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Expand Down

0 comments on commit 37c942c

Please sign in to comment.