diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs index 6efc32d0e..991c1e524 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyPushCommandSpecs.cs @@ -147,6 +147,7 @@ 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); @@ -157,6 +158,7 @@ public void should_not_check_for_fallback_community_url() { reset(); configuration.Sources = ""; + configuration.PushCommand.DefaultSource = ""; configSettingsService.Setup(c => c.get_api_key( It.Is(config => config.Sources.is_equal_to(ApplicationParameters.ChocolateyCommunityFeedPushSourceOld)), null)) @@ -171,6 +173,64 @@ public void should_not_check_for_fallback_community_url() configuration.PushCommand.Key.ShouldNotEqual(apiKey); } + [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_throw_when_defaultpushsource_is_disabled_and_no_explicit_sources() + { + reset(); + configuration.PushCommand.DefaultSource = "disabled"; + configuration.Sources = ""; + + 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() + { + reset(); + configuration.Sources = "https://somewhere/out/there"; + configuration.PushCommand.Key = "bob"; + configuration.PushCommand.DefaultSource = "disabled"; + because(); + } + [Fact] public void should_not_set_the_apiKey_if_source_is_not_found() { @@ -244,6 +304,25 @@ public void should_update_source_if_alias_is_passed() configuration.Sources.ShouldEqual("https://localhost/somewhere/out/there"); } + + [Fact] + public void should_update_source_if_alias_is_passed_via_defaultpushsource() + { + reset(); + configuration.Sources = ""; + configuration.PushCommand.DefaultSource = "myrepo"; + configuration.MachineSources = new List + { + new MachineSourceConfiguration + { + Name = "myrepo", + Key = "https://localhost/somewhere/out/there" + } + }; + because(); + + configuration.Sources.ShouldEqual("https://localhost/somewhere/out/there"); + } } public class when_handling_validation : ChocolateyPushCommandSpecsBase