From 9533572fe96633cb0082beb105750690b04ba7d8 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Wed, 4 Jan 2023 18:10:10 -0600 Subject: [PATCH] (#2409)(#508) Add tests for uppercase package ID This adds integration tests to ensure that packages that have IDs with uppercase character(s) can be installed, upgraded, listed, and uninstalled. --- .../context/uppercase/1.0.0/UpperCase.nuspec | 18 +++ .../1.0.0/tools/chocolateyBeforeModify.ps1 | 1 + .../1.0.0/tools/chocolateyinstall.ps1 | 1 + .../1.0.0/tools/chocolateyuninstall.ps1 | 1 + .../context/uppercase/1.1.0/UpperCase.nuspec | 18 +++ .../1.1.0/tools/chocolateyBeforeModify.ps1 | 1 + .../1.1.0/tools/chocolateyinstall.ps1 | 1 + .../1.1.0/tools/chocolateyuninstall.ps1 | 1 + .../scenarios/InstallScenarios.cs | 115 ++++++++++++++ .../scenarios/ListScenarios.cs | 52 +++++++ .../scenarios/UninstallScenarios.cs | 87 +++++++++++ .../scenarios/UpgradeScenarios.cs | 143 ++++++++++++++++++ 12 files changed, 439 insertions(+) create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.0.0/UpperCase.nuspec create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyBeforeModify.ps1 create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyinstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyuninstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.1.0/UpperCase.nuspec create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyBeforeModify.ps1 create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyinstall.ps1 create mode 100644 src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyuninstall.ps1 diff --git a/src/chocolatey.tests.integration/context/uppercase/1.0.0/UpperCase.nuspec b/src/chocolatey.tests.integration/context/uppercase/1.0.0/UpperCase.nuspec new file mode 100644 index 0000000000..7e27d66f1a --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/1.0.0/UpperCase.nuspec @@ -0,0 +1,18 @@ + + + + UpperCase + 1.0.0 + UpperCase + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + UpperCase admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..af5bb142e8 --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Before Modification" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/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/uppercase/1.0.0/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/uppercase/1.0.0/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/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/uppercase/1.1.0/UpperCase.nuspec b/src/chocolatey.tests.integration/context/uppercase/1.1.0/UpperCase.nuspec new file mode 100644 index 0000000000..c5ec5c2a80 --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/1.1.0/UpperCase.nuspec @@ -0,0 +1,18 @@ + + + + UpperCase + 1.1.0 + UpperCase + __REPLACE_AUTHORS_OF_SOFTWARE__ + __REPLACE_YOUR_NAME__ + false + __REPLACE__ + __REPLACE__ + + UpperCase admin + + + + + \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyBeforeModify.ps1 b/src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyBeforeModify.ps1 new file mode 100644 index 0000000000..af5bb142e8 --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyBeforeModify.ps1 @@ -0,0 +1 @@ +Write-Output "$env:PackageName $env:PackageVersion Before Modification" \ No newline at end of file diff --git a/src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyinstall.ps1 b/src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000000..d64eb8f47b --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/1.1.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/uppercase/1.1.0/tools/chocolateyuninstall.ps1 b/src/chocolatey.tests.integration/context/uppercase/1.1.0/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000000..9ead91ffa3 --- /dev/null +++ b/src/chocolatey.tests.integration/context/uppercase/1.1.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/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index 918c0ccc80..074b8620a4 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -4818,5 +4818,120 @@ public void should_have_success_package_results() } } } + + public class when_installing_a_package_with_an_uppercase_id : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Scenario.add_packages_to_source_location(Configuration, "UpperCase.1.0.0" + NuGetConstants.PackageExtension); + Configuration.PackageNames = Configuration.Input = "UpperCase"; + } + + public override void Because() + { + Results = Service.install_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_install_where_install_location_reports() + { + DirectoryAssert.Exists(_packageResult.InstallLocation); + } + + [Fact] + public void should_install_the_package_in_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + DirectoryAssert.Exists(packageDir); + } + + [Fact] + public void should_have_the_correct_casing_for_the_nuspec() + { + var nuspecFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.ManifestExtension); + FileAssert.Exists(nuspecFile); + } + + [Fact] + public void should_install_the_expected_version_of_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); + using (var packageReader = new PackageArchiveReader(packageFile)) + { + packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.0.0"); + } + } + + [Fact] + public void should_not_create_an_extensions_folder_for_the_package() + { + var extensionsDirectory = Path.Combine(Scenario.get_top_level(), "extensions", Configuration.PackageNames); + + DirectoryAssert.DoesNotExist(extensionsDirectory); + } + + [Fact] + public void should_not_create_an_hooks_folder_for_the_package() + { + var hooksDirectory = Path.Combine(Scenario.get_top_level(), "hooks", Configuration.PackageNames); + + DirectoryAssert.DoesNotExist(hooksDirectory); + } + + [Fact] + public void should_contain_a_warning_message_that_it_installed_successfully() + { + bool installedSuccessfully = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("1/1")) installedSuccessfully = true; + } + + installedSuccessfully.ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeFalse(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void config_should_match_package_result_name() + { + _packageResult.Name.ShouldEqual(Configuration.PackageNames); + } + + [Fact] + public void should_have_a_version_of_one_dot_zero_dot_zero() + { + _packageResult.Version.ShouldEqual("1.0.0"); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_have_executed_chocolateyInstall_script() + { + MockLogger.contains_message("UpperCase 1.0.0 Installed", LogLevel.Info).ShouldBeTrue(); + } + } } } diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs index 55c6a47b8e..5c08986d80 100644 --- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs @@ -759,5 +759,57 @@ public void should_find_all_versions_in_descending_order() Results[2].PackageMetadata.Version.ToNormalizedString().ShouldEqual("0.9.0"); } } + + public class when_listing_local_packages_with_uppercase_id_package_installed : ScenariosBase + { + public override void Context() + { + base.Context(); + Scenario.add_packages_to_source_location(Configuration, "UpperCase" + "*" + NuGetConstants.PackageExtension); + Scenario.install_package(Configuration, "UpperCase", "1.1.0"); + + Configuration.ListCommand.LocalOnly = true; + Configuration.Sources = ApplicationParameters.PackagesLocation; + } + + public override void Because() + { + MockLogger.reset(); + Results = Service.list_run(Configuration).ToList(); + } + + [Fact] + public void should_contain_packages_and_versions_with_a_space_between_them() + { + MockLogger.contains_message("upgradepackage 1.0.0").ShouldBeTrue(); + } + + [Fact] + public void should_contain_uppercase_id_package() + { + MockLogger.contains_message("UpperCase 1.1.0").ShouldBeTrue(); + } + + [Fact] + public void should_not_contain_packages_and_versions_with_a_pipe_between_them() + { + MockLogger.contains_message("upgradepackage|1.0.0").ShouldBeFalse(); + } + + [Fact] + public void should_contain_a_summary() + { + MockLogger.contains_message("packages installed").ShouldBeTrue(); + } + + [Fact] + public void should_contain_debugging_messages() + { + MockLogger.contains_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue(); + MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue(); + } + } } } diff --git a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs index c624bfd56a..cdc5180356 100644 --- a/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs @@ -1322,5 +1322,92 @@ public void should_have_executed_post_beforemodify_hook_script() } } + public class when_uninstalling_a_package_with_uppercase_id : ScenariosBase + { + private PackageResult packageResult; + + public override void Context() + { + base.Context(); + Scenario.add_packages_to_source_location(Configuration, "UpperCase" + "*" + NuGetConstants.PackageExtension); + Scenario.install_package(Configuration, "UpperCase", "1.1.0"); + + Configuration.PackageNames = Configuration.Input = "UpperCase"; + } + + public override void Because() + { + Results = Service.uninstall_run(Configuration); + packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_remove_the_package_from_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + DirectoryAssert.DoesNotExist(packageDir); + } + + [Fact] + public void should_delete_the_rollback() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib-bkp", Configuration.PackageNames); + + DirectoryAssert.DoesNotExist(packageDir); + } + + [Fact] + public void should_contain_a_warning_message_that_it_uninstalled_successfully() + { + bool installedSuccessfully = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("1/1")) installedSuccessfully = true; + } + + installedSuccessfully.ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + packageResult.Inconclusive.ShouldBeFalse(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void config_should_match_package_result_name() + { + packageResult.Name.ShouldEqual(Configuration.PackageNames); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_have_executed_chocolateyBeforeModify_script() + { + MockLogger.contains_message("UpperCase 1.1.0 Before Modification", LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_have_executed_chocolateyUninstall_script() + { + MockLogger.contains_message("UpperCase 1.1.0 Uninstalled", LogLevel.Info).ShouldBeTrue(); + } + } } } diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 05ab0a741f..4353f37ba7 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -4364,5 +4364,148 @@ public void should_not_have_executed_beforemodify_hook_script_for_upgrade_versio MockLogger.contains_message("pre-beforemodify-all.ps1 hook ran for upgradepackage 1.1.0", LogLevel.Info).ShouldBeFalse(); } } + public class when_upgrading_an_existing_package_with_uppercase_id : ScenariosBase + { + private PackageResult _packageResult; + + public override void Context() + { + base.Context(); + Scenario.add_packages_to_source_location(Configuration, "UpperCase" + "*" + NuGetConstants.PackageExtension); + Scenario.install_package(Configuration, "UpperCase", "1.0.0"); + + Configuration.PackageNames = Configuration.Input = "UpperCase"; + } + + public override void Because() + { + Results = Service.upgrade_run(Configuration); + _packageResult = Results.FirstOrDefault().Value; + } + + [Fact] + public void should_have_the_correct_casing_for_the_nuspec() + { + var nuspecFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.ManifestExtension); + FileAssert.Exists(nuspecFile); + } + + [Fact] + public void should_upgrade_where_install_location_reports() + { + DirectoryAssert.Exists(_packageResult.InstallLocation); + } + + [Fact] + public void should_upgrade_a_package_in_the_lib_directory() + { + var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); + + DirectoryAssert.Exists(packageDir); + } + + [Fact] + public void should_upgrade_the_package() + { + var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + NuGetConstants.PackageExtension); + using (var packageReader = new PackageArchiveReader(packageFile)) + { + packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.1.0"); + } + } + + [Fact] + public void should_contain_a_warning_message_that_it_upgraded_successfully() + { + bool upgradedSuccessMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("upgraded 1/1")) upgradedSuccessMessage = true; + } + + upgradedSuccessMessage.ShouldBeTrue(); + } + + [Fact] + public void should_contain_a_warning_message_with_old_and_new_versions() + { + bool upgradeMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) + { + if (message.Contains("You have UpperCase v1.0.0 installed. Version 1.1.0 is available based on your source")) upgradeMessage = true; + } + + upgradeMessage.ShouldBeTrue(); + } + + [Fact] + public void should_have_a_successful_package_result() + { + _packageResult.Success.ShouldBeTrue(); + } + + [Fact] + public void should_not_have_inconclusive_package_result() + { + _packageResult.Inconclusive.ShouldBeFalse(); + } + + [Fact] + public void should_not_have_warning_package_result() + { + _packageResult.Warning.ShouldBeFalse(); + } + + [Fact] + public void config_should_match_package_result_name() + { + _packageResult.Name.ShouldEqual(Configuration.PackageNames); + } + + [Fact] + public void should_match_the_upgrade_version_of_one_dot_one_dot_zero() + { + _packageResult.Version.ShouldEqual("1.1.0"); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_have_executed_chocolateyBeforeModify_script_for_original_package() + { + MockLogger.contains_message("UpperCase 1.0.0 Before Modification", LogLevel.Info).ShouldBeTrue(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_have_executed_chocolateyBeforeModify_before_chocolateyInstall() + { + MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null() + .SkipWhile(p => !p.Contains("UpperCase 1.0.0 Before Modification")) + .Any(p => p.EndsWith("UpperCase 1.1.0 Installed")) + .ShouldBeTrue(); + } + + [Fact] + public void should_not_have_executed_chocolateyUninstall_script_for_original_package() + { + MockLogger.contains_message("UpperCase 1.0.0 Uninstalled", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + public void should_not_have_executed_chocolateyBeforeModify_script_for_new_package() + { + MockLogger.contains_message("UpperCase 1.1.0 Before Modification", LogLevel.Info).ShouldBeFalse(); + } + + [Fact] + [WindowsOnly] + [Platform(Exclude = "Mono")] + public void should_have_executed_chocolateyInstall_script_for_new_package() + { + MockLogger.contains_message("UpperCase 1.1.0 Installed", LogLevel.Info).ShouldBeTrue(); + } + } } }