Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1092) Incorporate beforemodify changes into develop branch #3065

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>hasdependencywithbeforemodify</id>
<version>1.0.0</version>
<title>hasdependencywithbeforemodify</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<copyright />
<tags>hasdependencywithbeforemodify admin</tags>
<dependencies>
<dependency id="isdependencywithbeforemodify" version="[1.0.0, 2.0.0.0)" />
</dependencies>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion"
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 @@
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>hasdependencywithbeforemodify</id>
<version>2.0.0</version>
<title>hasdependencywithbeforemodify</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<copyright />
<tags>hasdependencywithbeforemodify admin</tags>
<dependencies>
<dependency id="isdependencywithbeforemodify" version="[2.0.0, 3.0.0.0)" />
</dependencies>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-Output "Ran BeforeModify: $env:PackageName $env:PackageVersion"
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 @@
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
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>isdependencywithbeforemodify</id>
<version>1.0.0</version>
<title>isdependencywithbeforemodify</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>isdependencywithbeforemodify 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 "Ran BeforeModify: $env:PackageName $env:PackageVersion"
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 @@
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
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>isdependencywithbeforemodify</id>
<version>2.0.0</version>
<title>isdependencywithbeforemodify</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>isdependencywithbeforemodify 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 "Ran BeforeModify: $env:PackageName $env:PackageVersion"
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 @@
This package is used to test out upgrade behaviour with beforeModify scripts in play for the main package and dependencies.
99 changes: 99 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
}
88 changes: 88 additions & 0 deletions src/chocolatey.tests.integration/scenarios/UninstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
}
}
}
Loading