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-490) Exception if no source is enabled #547

Closed
wants to merge 2 commits into from
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
18 changes: 15 additions & 3 deletions Scenarios.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Chocolatey Usage Scenarios

### ChocolateyInstallCommand [ 34 Scenario(s), 287 Observation(s) ]
### ChocolateyInstallCommand [ 35 Scenario(s), 288 Observation(s) ]

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

Expand Down Expand Up @@ -325,6 +325,10 @@
* [PENDING] should not install the conflicting package in the lib directory
* [PENDING] should not upgrade the exact version dependency

#### when installing a package with no sources enabled

* should have no sources enabled result

#### when installing a side by side package

* config should match package result name
Expand Down Expand Up @@ -391,7 +395,7 @@
* should not have inconclusive package result
* should not have warning package result

### ChocolateyListCommand [ 6 Scenario(s), 30 Observation(s) ]
### ChocolateyListCommand [ 7 Scenario(s), 31 Observation(s) ]

#### when listing local packages

Expand All @@ -408,6 +412,10 @@
* should not contain packages and versions with a space between them
* should only have messages related to package information

#### when listing packages with no sources enabled

* should have no sources enabled result

#### when searching all available packages

* should contain a summary
Expand Down Expand Up @@ -613,7 +621,7 @@

* should throw an error that it is not allowed

### ChocolateyUpgradeCommand [ 26 Scenario(s), 214 Observation(s) ]
### ChocolateyUpgradeCommand [ 27 Scenario(s), 215 Observation(s) ]

#### when force upgrading a package

Expand Down Expand Up @@ -853,6 +861,10 @@
* should upgrade the minimum version dependency
* should upgrade the package

#### when upgrading a package with no sources enabled

* should have no sources enabled result

#### when upgrading a package with readonly files

* should contain a warning message that it upgraded successfully
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 @@ -3333,5 +3333,29 @@ public void should_add_the_insert_value_in_the_config_due_to_XDT_InsertIfMissing
_xPathNavigator.SelectSingleNode("//configuration/appSettings/add[@key='insert']/@value").TypedValue.to_string().ShouldEqual("1.0.0");
}
}

[Concern(typeof(ChocolateyInstallCommand))]
public class when_installing_a_package_with_no_sources_enabled : ScenariosBase
{

public override void Context()
{
base.Context();
Configuration.Sources = null;
}

public override void Because()
{
MockLogger.reset();
Results = Service.install_run(Configuration);
}

[Fact]
public void should_have_no_sources_enabled_result()
{
MockLogger.contains_message("Installation was NOT successful. There are no sources enabled for packages.", LogLevel.Error).ShouldBeTrue();
Results.Count().ShouldEqual(0);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}
24 changes: 24 additions & 0 deletions src/chocolatey.tests.integration/scenarios/ListScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,29 @@ public void should_not_contain_debugging_messages()
MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeFalse();
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_listing_packages_with_no_sources_enabled : ScenariosBase
{

public override void Context()
{
base.Context();
Configuration.Sources = null;
}

public override void Because()
{
MockLogger.reset();
Results = Service.list_run(Configuration).ToList();
}

[Fact]
public void should_have_no_sources_enabled_result()
{
MockLogger.contains_message("Unable to search for packages when there are no sources enabled for packages.", LogLevel.Error).ShouldBeTrue();
Results.Count().ShouldEqual(0);
}
}
}
}
24 changes: 24 additions & 0 deletions src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2382,5 +2382,29 @@ public void should_have_a_config_with_the_comment_from_the_original()
}
}

[Concern(typeof(ChocolateyUpgradeCommand))]
public class when_upgrading_a_package_with_no_sources_enabled : ScenariosBase
{

public override void Context()
{
base.Context();
Configuration.Sources = null;
//Configuration.PackageNames = Configuration.Input = "installpackage";
}

public override void Because()
{
MockLogger.reset();
Results = Service.upgrade_run(Configuration);
}

[Fact]
public void should_have_no_sources_enabled_result()
{
MockLogger.contains_message("Upgrading was NOT successful. There are no sources enabled for packages.", LogLevel.Error).ShouldBeTrue();
Results.Count().ShouldEqual(0);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public void list_noop(ChocolateyConfiguration config)

public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config)
{
if (config.Sources == null)
{
this.Log().Error(ChocolateyLoggers.Important, @"Unable to search for packages when there are no sources enabled for packages.");
Environment.ExitCode = 1;
yield break;
}

if (config.RegularOutput) this.Log().Debug(() => "Searching for package information");

var packages = new List<IPackage>();
Expand Down Expand Up @@ -304,10 +311,18 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
{
this.Log().Info(@"Installing the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));
this.Log().Info(@"By installing you accept licenses for the packages.");

var packageInstalls = new ConcurrentDictionary<string, PackageResult>();

if (config.Sources == null)
{
this.Log().Error(ChocolateyLoggers.Important, @"Installation was NOT successful. There are no sources enabled for packages.");
Environment.ExitCode = 1;
return packageInstalls;
}

this.Log().Info(@"By installing you accept licenses for the packages.");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is also necessary for upgrade_run.

foreach (var packageConfig in set_config_from_package_names_and_packages_config(config, packageInstalls).or_empty_list_if_null())
{
Action<PackageResult> action = null;
Expand Down Expand Up @@ -497,6 +512,14 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
{
this.Log().Info(@"Upgrading the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

if (config.Sources == null)
{
this.Log().Error(ChocolateyLoggers.Important, @"Upgrading was NOT successful. There are no sources enabled for packages.");
Environment.ExitCode = 1;
return new ConcurrentDictionary<string, PackageResult>();
}

this.Log().Info(@"By upgrading you accept licenses for the packages.");

foreach (var packageConfigFile in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Where(p => p.EndsWith(".config")).ToList())
Expand Down