Skip to content

Commit

Permalink
(chocolatey#508) Add E2E tests for multiple uninstalls
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed May 2, 2023
1 parent e11a690 commit efa2623
Showing 1 changed file with 195 additions and 0 deletions.
195 changes: 195 additions & 0 deletions tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,201 @@ Describe "choco uninstall" -Tag Chocolatey, UninstallCommand {
}
}

Context "When specifying multiple packages where one is a dependency should not fail uninstallation" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$null = Invoke-Choco install hasdependency --confirm

$Output = Invoke-Choco uninstall isdependency hasdependency --confirm
}

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

# When a file exists before initial installation, it will be considered as part of the
# package files. This is NuGet behavior. This happens during existing files for upgrades as well.
# We might want to rollback files in this case, but it is not possible as the backup has been removed before
# any locked files are being tried to be removed.
It "Should have removed <_>" -ForEach @('isdependency', 'hasdependency') -Tag FossOnly {
"$env:ChocolateyInstall\lib\$_" | Should -Not -Exist -Because $Output.String
}

It "Should not have removed isexactversiondependency" {
"$env:ChocolateyInstall\lib\isexactversiondependency" | Should -Exist -Because $Output.String
}

It "Outputs <_> was succcesfully uninstalled" -ForEach @('isdependency', 'hasdependency') -Tag FossOnly {
$Output.Lines | Should -Contain "$_ has been successfully uninstalled." -Because $Output.String
}

It "Does not output isexactversiondependency being uninstalled" {
$Output.Lines | Should -Not -Contain "isexactversiondependency has been successfully uninstalled." -Because $Output.String
}

It "Outputs 2/2 packages uninstalled" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 2/2 packages." -Because $Output.String
}
}

Context "When specifying multiple packages where one is a dependency should not fail uninstallation (forced dependencies)" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$null = Invoke-Choco install hasdependency --confirm

$Output = Invoke-Choco uninstall isdependency hasdependency --confirm --force-dependencies
}

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

# This does not work as expected when runnning in test kitchen and with Chocolatey Licensed Extension installed.
# It is believed to be a problem with test kitchen, or the VM that we are using that is causing the issue.
# The result is that versioned backup files of each file in the package is created, instead of the package being
# removed. Consider the test partially broken.
It "Should have removed <_>" -ForEach @('isdependency', 'hasdependency', 'isexactversiondependency') -Tag FossOnly {
"$env:ChocolateyInstall\lib\$_" | Should -Not -Exist -Because $Output.String
}

It "Outputs <_> was succcesfully uninstalled" -ForEach @('isdependency', 'hasdependency', 'isexactversiondependency') {
$Output.Lines | Should -Contain "$_ has been successfully uninstalled." -Because $Output.String
}

It "Outputs 3/3 packages uninstalled" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 3/3 packages." -Because $Output.String
}
}

Context "When specifying non-existing package before and after failing package does not abort execution" {
BeforeAll {
$null = Invoke-Choco install uninstallfailure installpackage --confirm

$Output = Invoke-Choco uninstall packageA uninstallfailure packageB installpackage --confirm
}

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

It "Outputs package not existing (<_>)" -ForEach @('packageA', 'packageB') {
$Output.Lines | Should -Contain "$_ is not installed. Cannot uninstall a non-existent package." -Because $Output.String
$Output.Lines | Should -Contain "- $_ - $_ is not installed. Cannot uninstall a non-existent package." -Because $Output.String
}

It "Outputs failing to uninstall package uninstallfailure" {
$Output.Lines | Should -Contain "uninstallfailure not uninstalled. An error occurred during uninstall:" -Because $Output.String
$Output.Lines | Should -Contain "uninstallfailure uninstall not successful." -Because $Output.String
$Output.String | Should -Match "- uninstallfailure \(exited -1\) - Error while running"
}

# This does not work as expected when runnning in test kitchen and with Chocolatey Licensed Extension installed.
# It is believed to be a problem with test kitchen, or the VM that we are using that is causing the issue.
# The result is that versioned backup files of each file in the package is created, instead of the package being
# removed. Consider the test partially broken.
It "Should have uninstall package installpackage" -Tag FossOnly {
"$env:ChocolateyInstall\lib\installpackage" | Should -Not -Exist -Because $Output.String
}

# This does not work as expected when runnning in test kitchen and with Chocolatey Licensed Extension installed.
# It is believed to be a problem with test kitchen, or the VM that we are using that is causing the issue.
# The result is that versioned backup files of each file in the package is created, instead of the package being
# removed. Consider the test partially broken.
It "Outputs successful uninstall of installpackage" -Tag FossOnly {
$Output.Lines | Should -Contain "installpackage has been successfully uninstalled." -Because $Output.String
}

It "Outputs 1/3 successful uninstalls" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 1/4 packages. 3 packages failed." -Because $Output.String
}
}

Context "When specifying multiple packages where one is a nested dependency should not fail uninstallation" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$null = Invoke-Choco install toplevelwithnesteddependencies --confirm

$Output = Invoke-Choco uninstall isdependency toplevelwithnesteddependencies --confirm
}

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

# This does not work as expected when runnning in test kitchen and with Chocolatey Licensed Extension installed.
# It is believed to be a problem with test kitchen, or the VM that we are using that is causing the issue.
# The result is that versioned backup files of each file in the package is created, instead of the package being
# removed. Consider the test partially broken.
It "Should have removed package toplevelwithnesteddependencies" -Tag FossOnly {
"$env:ChocolateyInstall\lib\toplevelwithnesteddependencies" | Should -Not -Exist -Because $Output.String
}

It "Should not have removed <_>" -ForEach @('hasdependency', 'hasnesteddependency', 'isdependency', 'isexactversiondependency', 'toplevelhasexactversiondependency') {
"$env:ChocolateyInstall\lib\$_" | Should -Exist -Because $Output.String
}

It "Outputs toplevelwithnesteddependencies was succcesfully uninstalled" {
$Output.Lines | Should -Contain "toplevelwithnesteddependencies has been successfully uninstalled." -Because $Output.String
}

It "Does not output <_> being uninstalled" -ForEach @('hasdependency', 'hasnesteddependency', 'isdependency', 'isexactversiondependency', 'toplevelhasexactversiondependency') {
$Output.Lines | Should -Not -Contain "$_ has been successfully uninstalled." -Because $Output.String
}

It "Outputs warning about package being unable to be uninstalled due to being a dependency" {
$Output.Lines | Should -Contain "[NuGet]: Unable to uninstall 'isdependency.2.1.0' because 'hasdependency.2.0.1' depends on it."
}

It "Outputs 1/2 packages uninstalled with 1 failed package" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 1/2 packages. 1 packages failed." -Because $Output.String
}

It "Outputs failure to uninstall one of the packages" {
$Output.Lines | Should -Contain "- isdependency - Unable to uninstall 'isdependency.2.1.0' because 'hasdependency.2.0.1' depends on it."
}
}

Context "When specifying multiple packages where one is a nested dependency should not fail uninstallation (forced dependencies)" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$null = Invoke-Choco install toplevelwithnesteddependencies --confirm

$Output = Invoke-Choco uninstall isdependency toplevelwithnesteddependencies --confirm --force-dependencies
}

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

# This does not work as expected when runnning in test kitchen and with Chocolatey Licensed Extension installed.
# It is believed to be a problem with test kitchen, or the VM that we are using that is causing the issue.
# The result is that versioned backup files of each file in the package is created, instead of the package being
# removed. Consider the test partially broken.
It "Should have removed <_>" -ForEach @('hasdependency', 'hasnesteddependency', 'isdependency', 'isexactversiondependency', 'toplevelhasexactversiondependency', 'toplevelwithnesteddependencies') -Tag FossOnly {
"$env:ChocolateyInstall\lib\$_" | Should -Not -Exist -Because $Output.String
}

It "Outputs <_> was succcesfully uninstalled" -ForEach @('hasdependency', 'hasnesteddependency', 'isdependency', 'isexactversiondependency', 'toplevelhasexactversiondependency', 'toplevelwithnesteddependencies') {
$Output.Lines | Should -Contain "$_ has been successfully uninstalled." -Because $Output.String
}

It "Outputs warning about package being unable to be uninstalled due to being a dependency" {
$Output.Lines | Should -Contain "[NuGet]: Unable to uninstall 'isdependency.2.1.0' because 'hasdependency.2.0.1' depends on it."
}

It "Outputs 7/7 packages uninstalled" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 7/7 packages." -Because $Output.String
}

It "Does not output failure to uninstall one of the packages" {
$Output.Lines | Should -Not -Contain "- isdependency - Unable to uninstall 'isdependency.2.1.0' because 'hasdependency.2.0.1' depends on it."
}
}

# This needs to be the last test in this block, to ensure NuGet configurations aren't being created.
Test-NuGetPaths
}

0 comments on commit efa2623

Please sign in to comment.