From 7acbd15758de6caae2048deead0c3963ddab2648 Mon Sep 17 00:00:00 2001 From: Rain Sallow Date: Fri, 10 Mar 2023 16:51:12 -0500 Subject: [PATCH] (#1092) Add tests for dependencies' beforeModify This test added ensures that when we are upgrading a package, both its own and any dependencies' beforeModify are run so that we can properly update dependencies which might need to shut down a long-running service before being upgraded. (cherry picked from commit 49cc8d7e2cd4e03d02854b7cdf81acb9fe9f7015) # Conflicts: # src/chocolatey.tests.integration/chocolatey.tests.integration.csproj # src/chocolatey.tests.integration/scenarios/InstallScenarios.cs # src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs # src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs --- .../hasdependencywithbeforemodify.nuspec | 22 +++ .../1.0.0/tools/chocolateyBeforeModify.ps1 | 1 + .../1.0.0/tools/chocolateyinstall.ps1 | 1 + .../1.0.0/tools/chocolateyuninstall.ps1 | 1 + .../1.0.0/tools/purpose.txt | 1 + .../hasdependencywithbeforemodify.nuspec | 22 +++ .../2.0.0/tools/chocolateyBeforeModify.ps1 | 1 + .../2.0.0/tools/chocolateyinstall.ps1 | 1 + .../2.0.0/tools/chocolateyuninstall.ps1 | 1 + .../2.0.0/tools/purpose.txt | 1 + .../1.0.0/isdependencywithbeforemodify.nuspec | 18 ++ .../1.0.0/tools/chocolateyBeforeModify.ps1 | 1 + .../1.0.0/tools/chocolateyinstall.ps1 | 1 + .../1.0.0/tools/chocolateyuninstall.ps1 | 1 + .../1.0.0/tools/purpose.txt | 1 + .../2.0.0/isdependencywithbeforemodify.nuspec | 18 ++ .../2.0.0/tools/chocolateyBeforeModify.ps1 | 1 + .../2.0.0/tools/chocolateyinstall.ps1 | 1 + .../2.0.0/tools/chocolateyuninstall.ps1 | 1 + .../2.0.0/tools/purpose.txt | 1 + .../scenarios/InstallScenarios.cs | 99 +++++++++++ .../scenarios/UninstallScenarios.cs | 88 ++++++++++ .../scenarios/UpgradeScenarios.cs | 164 ++++++++++++++++++ 23 files changed, 447 insertions(+) create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/hasdependencywithbeforemodify.nuspec create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/purpose.txt create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/hasdependencywithbeforemodify.nuspec create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/purpose.txt create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/isdependencywithbeforemodify.nuspec create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/purpose.txt create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/isdependencywithbeforemodify.nuspec create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/purpose.txt diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/hasdependencywithbeforemodify.nuspec b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/hasdependencywithbeforemodify.nuspec new file mode 100644 index 0000000000..b458c99e13 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/hasdependencywithbeforemodify.nuspec @@ -0,0 +1,22 @@ + + + + hasdependencywithbeforemodify + 1.0.0 + hasdependencywithbeforemodify + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + + hasdependencywithbeforemodify admin + + + + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..d7bc904e0f --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Uninstalled" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/purpose.txt new file mode 100644 index 0000000000..5032f1e436 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/1.0.0/tools/purpose.txt @@ -0,0 +1 @@ +This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies. \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/hasdependencywithbeforemodify.nuspec b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/hasdependencywithbeforemodify.nuspec new file mode 100644 index 0000000000..ad40c22bc8 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/hasdependencywithbeforemodify.nuspec @@ -0,0 +1,22 @@ + + + + hasdependencywithbeforemodify + 2.0.0 + hasdependencywithbeforemodify + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + + hasdependencywithbeforemodify admin + + + + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..d7bc904e0f --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Uninstalled" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/purpose.txt new file mode 100644 index 0000000000..5032f1e436 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/hasdependencywithbeforemodify/2.0.0/tools/purpose.txt @@ -0,0 +1 @@ +This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies. \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/isdependencywithbeforemodify.nuspec b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/isdependencywithbeforemodify.nuspec new file mode 100644 index 0000000000..f81eaa394b --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/isdependencywithbeforemodify.nuspec @@ -0,0 +1,18 @@ + + + + isdependencywithbeforemodify + 1.0.0 + isdependencywithbeforemodify + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + isdependencywithbeforemodify admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..d7bc904e0f --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyinstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/chocolateyuninstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Uninstalled" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/purpose.txt new file mode 100644 index 0000000000..5032f1e436 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/1.0.0/tools/purpose.txt @@ -0,0 +1 @@ +This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies. \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/isdependencywithbeforemodify.nuspec b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/isdependencywithbeforemodify.nuspec new file mode 100644 index 0000000000..cba1fb9059 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/isdependencywithbeforemodify.nuspec @@ -0,0 +1,18 @@ + + + + isdependencywithbeforemodify + 2.0.0 + isdependencywithbeforemodify + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + isdependencywithbeforemodify admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..d7bc904e0f --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyinstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Installed" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/chocolateyuninstall.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Uninstalled" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/purpose.txt new file mode 100644 index 0000000000..5032f1e436 --- /dev/null +++ b/src/chocolatey.tests.integration/context/dependenciesbeforemodify/isdependencywithbeforemodify/2.0.0/tools/purpose.txt @@ -0,0 +1 @@ +This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies. \ No newline at end of file diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index 1e0e91effb..98a825d1b8 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -5461,5 +5461,104 @@ public override void Context() Configuration.Version = NonNormalizedVersion; } } + + public class when_installing_a_package_that_requires_updating_a_dependency : ScenariosBase + { + private const string TargetPackageName = "hasdependencywithbeforemodify"; + private const string DependencyName = "isdependencywithbeforemodify"; + + public override void Context() + { + base.Context(); + + Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(TargetPackageName) + NuGetConstants.PackageExtension); + Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(DependencyName) + NuGetConstants.PackageExtension); + Scenario.install_package(Configuration, DependencyName, "1.0.0"); + + Configuration.PackageNames = Configuration.Input = TargetPackageName; + } + + public override void Because() + { + Results = Service.install_run(Configuration); + } + + [Fact] + public void should_install_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", TargetPackageName, "{0}.nupkg".format_with(TargetPackageName)); + using (var packageReader = new PackageArchiveReader(packageFile)) + { + packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0"); + } + } + + [Fact] + public void should_upgrade_the_minimum_version_dependency() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".format_with(DependencyName)); + using (var packageReader = new PackageArchiveReader(packageFile)) + { + packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0"); + } + } + + [Fact] + public void should_contain_a_message_that_everything_installed_successfully() + { + MockLogger.contains_message("installed 2/2", LogLevel.Warn).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_not_run_target_package_beforeModify_for_upgraded_version() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(TargetPackageName, "2.0.0"), LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_already_installed_dependency_package_beforeModify() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_not_run_dependency_package_beforeModify_for_upgraded_version() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "2.0.0"), LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Success.ShouldBeTrue(); + } + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Inconclusive.ShouldBeFalse(); + } + } + + [Fact] + public void should_not_have_warning_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Warning.ShouldBeFalse(); + } + } + } } } diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index f549f40c92..e2c3511279 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -1527,5 +1527,93 @@ public void should_have_executed_chocolateyUninstall_script() MockLogger.contains_message("upgradepackage {0} Uninstalled".format_with(NonNormalizedVersion), LogLevel.Info).ShouldBeTrue(); } } + + public class when_uninstalling_a_package_with_remove_dependencies_with_beforeModify : ScenariosBase + { + private const string TargetPackageName = "hasdependencywithbeforemodify"; + private const string DependencyName = "isdependencywithbeforemodify"; + + public override void Context() + { + base.Context(); + + Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(TargetPackageName) + NuGetConstants.PackageExtension); + Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(DependencyName) + NuGetConstants.PackageExtension); + Scenario.install_package(Configuration, TargetPackageName, "1.0.0"); + Scenario.install_package(Configuration, DependencyName, "1.0.0"); + + Configuration.PackageNames = Configuration.Input = TargetPackageName; + Configuration.ForceDependencies = true; + } + + public override void Because() + { + Results = Service.uninstall_run(Configuration); + } + + [Fact] + public void should_uninstall_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", TargetPackageName, "{0}.nupkg".format_with(TargetPackageName)); + File.Exists(packageFile).ShouldBeFalse(); + } + + [Fact] + public void should_uninstall_the_dependency() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".format_with(DependencyName)); + File.Exists(packageFile).ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_message_that_everything_uninstalled_successfully() + { + MockLogger.contains_message("uninstalled 2/2", LogLevel.Warn).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_target_package_beforeModify() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(TargetPackageName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_dependency_package_beforeModify() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Success.ShouldBeTrue(); + } + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Inconclusive.ShouldBeFalse(); + } + } + + [Fact] + public void should_not_have_warning_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Warning.ShouldBeFalse(); + } + + } + } } } diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index c1a95f19d5..3ed7a8ae53 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -5373,5 +5373,169 @@ public override void Context() } } + + public class when_upgrading_a_package_with_beforeModify_script_with_dependencies_with_beforeModify_scripts_and_hooks : ScenariosBase + { + private const string TargetPackageName = "hasdependencywithbeforemodify"; + private const string DependencyName = "isdependencywithbeforemodify"; + + public override void Context() + { + base.Context(); + + Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(TargetPackageName) + NuGetConstants.PackageExtension); + Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(DependencyName) + NuGetConstants.PackageExtension); + Scenario.add_packages_to_source_location(Configuration, "scriptpackage.hook" + "*" + NuGetConstants.PackageExtension); + Scenario.install_package(Configuration, DependencyName, "1.0.0"); + Scenario.install_package(Configuration, TargetPackageName, "1.0.0"); + Scenario.install_package(Configuration, "scriptpackage.hook", "1.0.0"); + + Configuration.PackageNames = Configuration.Input = TargetPackageName; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + } + + [Fact] + public void should_upgrade_the_minimum_version_dependency() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", DependencyName, "{0}.nupkg".format_with(DependencyName)); + using (var packageReader = new PackageArchiveReader(packageFile)) + { + packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0"); + } + } + + [Fact] + public void should_contain_a_message_that_everything_upgraded_successfully() + { + MockLogger.contains_message("upgraded 2/2", LogLevel.Warn).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_beforemodify_hook_script_for_previous_version_of_target() + { + MockLogger.contains_message("pre-beforemodify-all.ps1 hook ran for {0} {1}".format_with(TargetPackageName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_already_installed_target_package_beforeModify() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(TargetPackageName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_not_run_beforemodify_hook_script_for_upgrade_version_of_target() + { + MockLogger.contains_message("pre-beforemodify-all.ps1 hook ran for {0} {1}".format_with(TargetPackageName, "2.0.0"), LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_not_run_target_package_beforeModify_for_upgraded_version() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(TargetPackageName, "2.0.0"), LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_pre_all_hook_script_for_upgraded_version_of_target() + { + MockLogger.contains_message("pre-install-all.ps1 hook ran for {0} {1}".format_with(TargetPackageName, "2.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_post_all_hook_script_for_upgraded_version_of_target() + { + MockLogger.contains_message("post-install-all.ps1 hook ran for {0} {1}".format_with(TargetPackageName, "2.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_beforemodify_hook_script_for_previous_version_of_dependency() + { + MockLogger.contains_message("pre-beforemodify-all.ps1 hook ran for {0} {1}".format_with(DependencyName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_already_installed_dependency_package_beforeModify() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "1.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_not_run_beforemodify_hook_script_for_upgrade_version_of_dependency() + { + MockLogger.contains_message("pre-beforemodify-all.ps1 hook ran for {0} {1}".format_with(DependencyName, "2.0.0"), LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_not_run_dependency_package_beforeModify_for_upgraded_version() + { + MockLogger.contains_message("Ran BeforeModify: {0} {1}".format_with(DependencyName, "2.0.0"), LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_pre_all_hook_script_for_upgraded_version_of_dependency() + { + MockLogger.contains_message("pre-install-all.ps1 hook ran for {0} {1}".format_with(DependencyName, "2.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_run_post_all_hook_script_for_upgraded_version_of_dependency() + { + MockLogger.contains_message("post-install-all.ps1 hook ran for {0} {1}".format_with(DependencyName, "2.0.0"), LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Success.ShouldBeTrue(); + } + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Inconclusive.ShouldBeFalse(); + } + } + + [Fact] + public void should_not_have_warning_package_result() + { + foreach (var packageResult in Results) + { + packageResult.Value.Warning.ShouldBeFalse(); + } + } + } } }