Skip to content

Commit

Permalink
(#3461) Add downgrade install pester test
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed Jul 18, 2024
1 parent 5b2cb7c commit c3c71b6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/pester-tests/commands/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,54 @@ To install a local, or remote file, you may use:
}
}

Context 'Installing a package should not downgrade an existing package dependency.' -Tag Downgrade {
BeforeAll {
$DependentPackage = @{
Name = 'isexactversiondependency'
Version = '2.0.0'
}

Restore-ChocolateyInstallSnapshot

$Setup = Invoke-Choco install $DependentPackage.Name --version $DependentPackage.Version --confirm
$Output = Invoke-Choco install toplevelhasexactversiondependency
}

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

It "Reports that it cannot downgrade isexactversiondependency" {
$Output.Lines | Should -Contain 'A newer version of isexactversiondependency (v2.0.0) is already installed.' -Because $Output.String
$Output.Lines | Should -Contain 'Use --allow-downgrade or --force to attempt to install older versions.' -Because $Output.String
$Output.Lines | Should -Contain 'Chocolatey installed 0/3 packages. 3 packages failed.' -Because $Output.String
}
}

Context 'Installing a package should downgrade an existing package dependency when <_> is used.' -ForEach @('--force', '--allow-downgrade') -Tag Downgrade {
BeforeAll {
$DependentPackage = @{
Name = 'isexactversiondependency'
Version = '2.0.0'
}

Restore-ChocolateyInstallSnapshot

$Setup = Invoke-Choco install $DependentPackage.Name --version $DependentPackage.Version --confirm
$Output = Invoke-Choco install toplevelhasexactversiondependency $_
}

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

It "Does not report that it cannot downgrade isexactversiondependency" {
$Output.Lines | Should -Not -Contain 'A newer version of isexactversiondependency (v2.0.0) is already installed.' -Because $Output.String
$Output.Lines | Should -Not -Contain 'Use --allow-downgrade or --force to attempt to install older versions.' -Because $Output.String
$Output.Lines | Should -Contain 'Chocolatey installed 3/3 packages.' -Because $Output.String
}
}

# This needs to be the last test in this block, to ensure NuGet configurations aren't being created.
# Any tests after this block are expected to generate the configuration as they're explicitly using the NuGet CLI
Test-NuGetPaths
Expand Down

0 comments on commit c3c71b6

Please sign in to comment.