Skip to content

Commit

Permalink
(#2409)(#508) Add tests for uppercase package ID
Browse files Browse the repository at this point in the history
This adds integration tests to ensure that packages that have IDs
with uppercase character(s) can be installed, upgraded, listed,
and uninstalled.
  • Loading branch information
TheCakeIsNaOH authored and gep13 committed Jan 6, 2023
1 parent d844857 commit 153516d
Show file tree
Hide file tree
Showing 12 changed files with 439 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>UpperCase</id>
<version>1.0.0</version>
<title>UpperCase</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>UpperCase admin</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Before Modification"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>UpperCase</id>
<version>1.1.0</version>
<title>UpperCase</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>UpperCase admin</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Before Modification"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Installed"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "$env:PackageName $env:PackageVersion Uninstalled"
115 changes: 115 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
52 changes: 52 additions & 0 deletions src/chocolatey.tests.integration/scenarios/ListScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
87 changes: 87 additions & 0 deletions src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
Loading

0 comments on commit 153516d

Please sign in to comment.