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 22, 2022
1 parent 4a488f6 commit 80f8109
Show file tree
Hide file tree
Showing 2 changed files with 60 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 }
) -Tag Mine {
BeforeAll {
Restore-ChocolateyInstallSnapshot -SetWorkDir

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.Lines | Should -Contain "installpackage|1.0.0"
}
else {
$Output.Lines | Should -Not -Contain "installpackage|1.0.0"
}
}
}

Context "Installing package that extracts local zip archive while disabling logging" {
BeforeAll {
Restore-ChocolateyInstallSnapshot
Expand Down
29 changes: 29 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,35 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand {
}
}

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

$Package = 'upgradepackage'
$null = Invoke-Choco install $Package --version 1.0.0 --confirm
$hmmm = Invoke-Choco upgrade $Package $Command --confirm
write-host $hmmm.string
write-host $hmmm.ExitCode
$Output = Invoke-Choco pin list
}

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

It "Output should include pinned package" {
if ($Contains) {
$Output.Lines | Should -Contain "$Package|1.1.0"
}
else {
$Output.Lines | Should -Not -Contain "$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 80f8109

Please sign in to comment.