From 96abeabfb665e8dfa651df6a3d57ed220b417673 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Thu, 28 Oct 2021 21:43:09 -0500 Subject: [PATCH] (#62) Add unit tests for DefaultPushSource Adds tests for DefaultPushSource to check it works correctly. If DefaultPushSource is set, it should set the source assuming that a source is not passed in explicitly with --source. If a source is passed in explicitly, then DefaultPushSource should not override it. If DefaultPushSource is set to "disabled", it should throw an error if there is not an explicit source passed in. But if an explicit source is passed in, it should not error. --- .../commands/ChocolateyPushCommandSpecs.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs index 238420715..46bb4e280 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs @@ -145,11 +145,34 @@ public void should_set_the_source_to_default_feed_if_not_set_explicitly() { reset(); configuration.Sources = ""; + configuration.PushCommand.DefaultSource = string.Empty; because(); configuration.Sources.ShouldEqual(ApplicationParameters.ChocolateyCommunityFeedPushSource); } + [Fact] + public void should_set_the_source_to_defaultpushsource_if_set_and_no_explicit_source() + { + reset(); + configuration.Sources = ""; + configuration.PushCommand.DefaultSource = "https://localhost/default/source"; + because(); + + configuration.Sources.ShouldEqual("https://localhost/default/source"); + } + + [Fact] + public void should_not_override_explicit_source_if_defaultpushsource_is_set() + { + reset(); + configuration.Sources = "https://localhost/somewhere/out/there"; + configuration.PushCommand.DefaultSource = "https://localhost/default/source"; + because(); + + configuration.Sources.ShouldEqual("https://localhost/somewhere/out/there"); + } + [Fact] public void should_not_set_the_apiKey_if_source_is_not_found() { @@ -312,6 +335,39 @@ public void should_continue_when_source_is_http_and_not_secure_if_force_is_passe because(); } + + [Fact] + public void should_throw_when_defaultpushsource_is_disabled_and_no_explicit_sources() + { + configuration.Sources = "disabled"; + + var errorred = false; + Exception error = null; + + try + { + because(); + } + catch (Exception ex) + { + errorred = true; + error = ex; + } + + errorred.ShouldBeTrue(); + error.ShouldNotBeNull(); + error.ShouldBeType(); + error.Message.ShouldContain("Default push source is disabled."); + } + + [Fact] + public void should_continue_when_defaultpushsource_is_disabled_and_explicit_sources_passed() + { + configuration.Sources = "https://somewhere/out/there"; + configuration.PushCommand.Key = "bob"; + configuration.PushCommand.DefaultSource = "disabled"; + because(); + } } public class when_noop_is_called : ChocolateyPushCommandSpecsBase