From 37c942c93c2691bb75087bbc7b7b1bc021f4895e Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Mon, 26 Sep 2022 06:56:00 -0700 Subject: [PATCH] (#798) Add tests for pinning package on install Add tests that we are pinning packages when during upgrade and install when done with the `--pin` parameter. --- .../chocolatey-tests/choco-install.Tests.ps1 | 31 +++++++++++++++++++ .../chocolatey-tests/choco-upgrade.Tests.ps1 | 27 ++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/tests/chocolatey-tests/choco-install.Tests.ps1 b/tests/chocolatey-tests/choco-install.Tests.ps1 index 2a810317b5..5039cbe3d1 100644 --- a/tests/chocolatey-tests/choco-install.Tests.ps1 +++ b/tests/chocolatey-tests/choco-install.Tests.ps1 @@ -1393,6 +1393,37 @@ Describe "choco install" -Tag Chocolatey, InstallCommand { } } + Context "Install '' package with () 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') { + @" + + + + +"@ | 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 diff --git a/tests/chocolatey-tests/choco-upgrade.Tests.ps1 b/tests/chocolatey-tests/choco-upgrade.Tests.ps1 index 25b8d785fc..593c1fdee2 100644 --- a/tests/chocolatey-tests/choco-upgrade.Tests.ps1 +++ b/tests/chocolatey-tests/choco-upgrade.Tests.ps1 @@ -120,6 +120,33 @@ Describe "choco upgrade" -Tag Chocolatey, UpgradeCommand { } } + Context "Upgrade package with () 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