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) Ensure chocolateyBeforeModify.ps1 is run for dependencies #3051

Merged
merged 3 commits into from
Mar 14, 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
Expand Up @@ -141,6 +141,54 @@
<None Include="context\badpackage\2.0\tools\chocolateyUninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\1.0.0\hasdependencywithbeforemodify.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\1.0.0\tools\chocolateyBeforeModify.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\2.0.0\hasdependencywithbeforemodify.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\2.0.0\tools\chocolateyBeforeModify.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\2.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\2.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\1.0.0\isdependencywithbeforemodify.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\1.0.0\tools\chocolateyBeforeModify.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\1.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\1.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\2.0.0\isdependencywithbeforemodify.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\2.0.0\tools\chocolateyBeforeModify.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\2.0.0\tools\chocolateyinstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\2.0.0\tools\chocolateyuninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\dependencies\conflictingdependency\1.0.1\conflictingdependency.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -661,6 +709,10 @@
<None Include="context\upgradepackage\1.1.0\tools\graphical.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\1.0.0\tools\purpose.txt" />
<Content Include="context\dependenciesbeforemodify\hasdependencywithbeforemodify\2.0.0\tools\purpose.txt" />
<Content Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\1.0.0\tools\purpose.txt" />
<Content Include="context\dependenciesbeforemodify\isdependencywithbeforemodify\2.0.0\tools\purpose.txt" />
<Content Include="context\exactpackage\exactpackage.dontfind\1.0.0\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
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>
corbob marked this conversation as resolved.
Show resolved Hide resolved
<releaseNotes />
<copyright />
<tags>hasdependencywithbeforemodify admin</tags>
<dependencies>
<dependency id="isdependencywithbeforemodify" version="[1.0.0, 2.0.0.0)" />
gep13 marked this conversation as resolved.
Show resolved Hide resolved
</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)" />
gep13 marked this conversation as resolved.
Show resolved Hide resolved
</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.
95 changes: 95 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4013,5 +4013,100 @@ public void should_not_have_executed_beforemodify_hook_script()
MockLogger.contains_message("pre-beforemodify-all.ps1 hook ran for portablepackage 1.0.0", LogLevel.Info).ShouldBeFalse();
}
}

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) + Constants.PackageExtension);
Scenario.add_packages_to_source_location(Configuration, "{0}.*".format_with(DependencyName) + Constants.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));
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("2.0.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));
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("2.0.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();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace chocolatey.tests.integration.scenarios
using System.Collections.Generic;
using System.Linq;
using chocolatey.infrastructure.app;
using chocolatey.infrastructure.app.commands;
using chocolatey.infrastructure.app.configuration;
using chocolatey.infrastructure.app.services;
using chocolatey.infrastructure.results;
Expand Down
Loading