Skip to content

Commit

Permalink
(chocolatey#1092) Update ISourceRunner install_run
Browse files Browse the repository at this point in the history
This addition is necessary, as many occasions may arise where installing
one package involves updating an already-installed dependency. In these
cases we should still be running a beforeModify script if it's present,
and this facilitates that.
  • Loading branch information
vexx32 committed Feb 28, 2023
1 parent 388b3f6 commit c692c04
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public override void Context()
var expectedResult = new ConcurrentDictionary<string, PackageResult>();
expectedResult.TryAdd("test-feature", new PackageResult(package.Object, "windowsfeatures", null));

FeaturesRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult>>()))
FeaturesRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult>>(), It.IsAny<Action<PackageResult>>()))
.Returns(expectedResult);
NormalRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult>>()))
NormalRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult>>(), It.IsAny<Action<PackageResult>>()))
.Returns(new ConcurrentDictionary<string, PackageResult>());
SourceRunners.AddRange(new[] { NormalRunner.Object, FeaturesRunner.Object });

Expand Down Expand Up @@ -125,20 +125,20 @@ public void should_return_package_that_should_have_been_installed()
[Test]
public void should_have_called_runner_for_windows_features_source()
{
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames == "test-feature"), It.IsAny<Action<PackageResult>>()), Times.Once);
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames == "test-feature"), It.IsAny<Action<PackageResult>>(), It.IsAny<Action<PackageResult>>()), Times.Once);
}

[Test]
public void should_not_have_called_runner_for_windows_features_source_with_other_package_names()
{
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != "test-feature"), It.IsAny<Action<PackageResult>>()), Times.Never);
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != "test-feature"), It.IsAny<Action<PackageResult>>(), It.IsAny<Action<PackageResult>>()), Times.Never);
}

[Test]
public void should_not_have_called_normal_source_runner_for_non_empty_packages()
{
// The normal source runners will be called with an argument
NormalRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != string.Empty), It.IsAny<Action<PackageResult>>()), Times.Never);
NormalRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != string.Empty), It.IsAny<Action<PackageResult>>(), It.IsAny<Action<PackageResult>>()), Times.Never);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
this.Log().Info("Would have run '{0} {1}'".format_with(get_exe(RootDirectory).escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null)
{
var args = build_args(config, _installArguments);
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
5 changes: 3 additions & 2 deletions src/chocolatey/infrastructure.app/services/ISourceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public interface ISourceRunner
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="continueAction">The action to continue with when install is successful.</param>
/// <param name="beforeModifyAction">The action (if any) to run on any currently installed package dependencies before triggering the install or updating those dependencies.</param>
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction);
ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null);

/// <summary>
/// Run upgrade in noop mode
Expand All @@ -89,7 +90,7 @@ public interface ISourceRunner
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="continueAction">The action to continue with when upgrade is successful.</param>
/// <param name="beforeUpgradeAction">The action (if any) to run on any currently installed package before triggering the upgrade.</param>
/// <param name="beforeUpgradeAction">The action (if any) to run on any currently installed package or its dependencies before triggering the upgrade.</param>
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUpgradeAction = null);

Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
ApplicationParameters.PackagesLocation = installLocation;
}

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null)
{
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackagesLocation);
var packageInstalls = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
this.Log().Info("Would have run '{0} {1}'".format_with(_exePath.escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null)
{
set_executable_path_if_not_set();
var args = build_args(config, _installArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH.escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null)
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var args = ExternalCommandArgsBuilder.build_arguments(config, _installArguments);
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/services/WebPiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH.escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null)
{
write_deprecation_warning();
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
this.Log().Info("Would have run '{0} {1}'".format_with(_exePath.escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction = null)
{
set_executable_path_if_not_set();
var args = build_args(config, _installArguments);
Expand Down

0 comments on commit c692c04

Please sign in to comment.