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 21, 2022
1 parent 5ff2f85 commit d66b9d6
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 @@ -1392,4 +1392,35 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$result2.Lines | Should -Contain "Circular dependency detected 'circulardependency2 0.0.1 => circulardependency1 0.0.1 => circulardependency2 0.0.1'."
}
}

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"
}
}
}
}
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 @@ -119,4 +119,33 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand {
$Output.Lines | Should -Contain "Chocolatey upgraded 1/1 packages." -Because $Output.String
}
}

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

0 comments on commit d66b9d6

Please sign in to comment.