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

(GH-878) Fixing install with packages.config - should print out the packages to install #880

Closed
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
4 changes: 3 additions & 1 deletion Scenarios.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Chocolatey Usage Scenarios

### ChocolateyInstallCommand [ 35 Scenario(s), 291 Observation(s) ]
### ChocolateyInstallCommand [ 35 Scenario(s), 293 Observation(s) ]

#### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies

Expand Down Expand Up @@ -362,6 +362,8 @@
* should not have a successful package result for missing package
* should not have inconclusive package result
* should not have warning package result
* should print out package from config file in message
* should specify config file is being used in message

#### when noop installing a package

Expand Down
24 changes: 24 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,30 @@ public void should_not_have_warning_package_result()
packageResult.Value.Warning.ShouldBeFalse();
}
}

[Fact]
public void should_specify_config_file_is_being_used_in_message()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
{
if (message.Contains("Installing from config file:")) expectedMessage = true;
}

expectedMessage.ShouldBeTrue();
}

[Fact]
public void should_print_out_package_from_config_file_in_message()
{
bool expectedMessage = false;
foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null())
{
if (message.Contains("installpackage")) expectedMessage = true;
}

expectedMessage.ShouldBeTrue();
}
}

[Concern(typeof(ChocolateyInstallCommand))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config)
{
this.Log().Info(@"Installing the following packages:");
this.Log().Info(is_packages_config_file(config) ? @"Installing from config file:" : @"Installing the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

var packageInstalls = new ConcurrentDictionary<string, PackageResult>();
Expand All @@ -446,6 +446,7 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
{
action = (packageResult) => handle_package_result(packageResult, packageConfig, CommandNameType.install);
}

var results = perform_source_runner_function(packageConfig, r => r.install_run(packageConfig, action));

foreach (var result in results)
Expand Down Expand Up @@ -524,13 +525,18 @@ private IEnumerable<ChocolateyConfiguration> set_config_from_package_names_and_p

foreach (var packageConfig in get_packages_from_config(packageConfigFile, config, packageInstalls).or_empty_list_if_null())
{
yield return packageConfig;
yield return packageConfig;
}
}

yield return config;
}

private bool is_packages_config_file(ChocolateyConfiguration config)
{
return config.PackageNames.Split(new[] {ApplicationParameters.PackageNamesSeparator}, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Any(p => p.EndsWith(".config"));
}

private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string packageConfigFile, ChocolateyConfiguration config, ConcurrentDictionary<string, PackageResult> packageInstalls)
{
IList<ChocolateyConfiguration> packageConfigs = new List<ChocolateyConfiguration>();
Expand All @@ -546,6 +552,7 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
}

var settings = _xmlService.deserialize<PackagesConfigFileSettings>(_fileSystem.get_full_path(packageConfigFile));
this.Log().Info(@"Installing the following packages:");
foreach (var pkgSettings in settings.Packages.or_empty_list_if_null())
{
if (!pkgSettings.Disabled)
Expand All @@ -560,6 +567,7 @@ private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string pac
if (pkgSettings.AllowMultipleVersions) packageConfig.AllowMultipleVersions = true;
if (pkgSettings.IgnoreDependencies) packageConfig.IgnoreDependencies = true;

this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(packageConfig.PackageNames));
packageConfigs.Add(packageConfig);
}
}
Expand Down