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 Mar 8, 2023
1 parent 030c57b commit 3a30cbc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 6 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
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/CygwinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction)
{
var args = build_args(config, _installArguments);
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
11 changes: 10 additions & 1 deletion src/chocolatey/infrastructure.app/services/ISourceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public interface ISourceRunner
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction);

/// <summary>
/// Installs packages from the source feed
/// </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, Action<PackageResult> beforeModifyAction);

/// <summary>
/// Run upgrade in noop mode
/// </summary>
Expand All @@ -89,7 +98,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
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction)
{
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackagesLocation);
var packageInstalls = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/PythonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction)
{
set_executable_path_if_not_set();
var args = build_args(config, _installArguments);
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/RubyGemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction)
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var args = ExternalCommandArgsBuilder.build_arguments(config, _installArguments);
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/WebPiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeModifyAction)
{
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 @@ -258,6 +258,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

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

0 comments on commit 3a30cbc

Please sign in to comment.