Skip to content

Commit

Permalink
Merge pull request #3079 from vexx32/2629-remove-ccr-default-push
Browse files Browse the repository at this point in the history
(#2629) Remove the CCR default push location
  • Loading branch information
corbob authored Mar 17, 2023
2 parents e5c6e1a + b86734f commit cacb4ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,6 @@ public void should_allow_a_path_to_the_nupkg_to_be_passed_in()
configuration.Input.ShouldEqual(nupkgPath);
}

[Fact]
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_not_check_for_fallback_community_url()
{
reset();
configuration.Sources = "";
configuration.PushCommand.DefaultSource = "";
configSettingsService.Setup(c => c.get_api_key(
It.Is<ChocolateyConfiguration>(config => config.Sources.is_equal_to(ApplicationParameters.ChocolateyCommunityFeedPushSourceOld)),
null))
.Returns(apiKey);
because();

configuration.Sources.ShouldEqual(ApplicationParameters.ChocolateyCommunityFeedPushSource);
configSettingsService.Verify(c => c.get_api_key(
It.Is<ChocolateyConfiguration>(config => config.Sources.is_equal_to(ApplicationParameters.ChocolateyCommunityFeedPushSourceOld)),
null),
Times.Never);
configuration.PushCommand.Key.ShouldNotEqual(apiKey);
}

[Fact]
public void should_set_the_source_to_defaultpushsource_if_set_and_no_explicit_source()
{
Expand All @@ -196,10 +165,10 @@ public void should_not_override_explicit_source_if_defaultpushsource_is_set()
}

[Fact]
public void should_throw_when_defaultpushsource_is_disabled_and_no_explicit_sources()
public void should_throw_when_defaultpushsource_is_not_set_and_no_explicit_sources()
{
reset();
configuration.PushCommand.DefaultSource = "disabled";
configuration.PushCommand.DefaultSource = "";
configuration.Sources = "";

var errorred = false;
Expand All @@ -218,16 +187,16 @@ public void should_throw_when_defaultpushsource_is_disabled_and_no_explicit_sour
errorred.ShouldBeTrue();
error.ShouldNotBeNull();
error.ShouldBeType<ApplicationException>();
error.Message.ShouldContain("Default push source is disabled.");
error.Message.ShouldContain("Default push source configuration is not set.");
}

[Fact]
public void should_continue_when_defaultpushsource_is_disabled_and_explicit_sources_passed()
public void should_continue_when_defaultpushsource_is_not_set_and_explicit_sources_passed()
{
reset();
configuration.Sources = "https://somewhere/out/there";
configuration.PushCommand.Key = "bob";
configuration.PushCommand.DefaultSource = "disabled";
configuration.PushCommand.DefaultSource = "";
because();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS
config.Proxy.BypassOnLocal = set_config_item(ApplicationParameters.ConfigSettings.ProxyBypassOnLocal, configFileSettings, "true", "Bypass proxy for local connections. Available in 0.10.4+.").is_equal_to(bool.TrueString);
config.UpgradeCommand.PackageNamesToSkip = set_config_item(ApplicationParameters.ConfigSettings.UpgradeAllExceptions, configFileSettings, string.Empty, "A comma-separated list of package names that should not be upgraded when running `choco upgrade all'. Defaults to empty. Available in 0.10.14+.");
config.DefaultTemplateName = set_config_item(ApplicationParameters.ConfigSettings.DefaultTemplateName, configFileSettings, string.Empty, "Default template name used when running 'choco new' command. Available in 0.12.0+.");
config.PushCommand.DefaultSource = set_config_item(ApplicationParameters.ConfigSettings.DefaultPushSource, configFileSettings, string.Empty, "Default source to push packages to when running 'choco push' command. Available in 0.12.0 +.");
config.PushCommand.DefaultSource = set_config_item(ApplicationParameters.ConfigSettings.DefaultPushSource, configFileSettings, string.Empty, "Default source to push packages to when running 'choco push' command. Available in 2.0.0+.");
}

private static string set_config_item(string configName, ConfigFileSettings configFileSettings, string defaultValue, string description, bool forceSettingValue = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,16 @@ public virtual void handle_additional_argument_parsing(IList<string> unparsedArg
{
configuration.Input = string.Join(" ", unparsedArguments); // path to .nupkg - assume relative

if (string.IsNullOrWhiteSpace(configuration.Sources) && !string.IsNullOrWhiteSpace(configuration.PushCommand.DefaultSource))
if (string.IsNullOrWhiteSpace(configuration.Sources))
{
configuration.Sources = configuration.PushCommand.DefaultSource;

// Can't put this in handle_validation, since "disabled" is not a URI, it would fail earlier
if (configuration.Sources.is_equal_to("disabled"))
if (!string.IsNullOrWhiteSpace(configuration.PushCommand.DefaultSource))
{
throw new ApplicationException("Default push source is disabled. Please pass a source to push to, such as --source={0}".format_with(ApplicationParameters.ChocolateyCommunityFeedPushSource));
configuration.Sources = configuration.PushCommand.DefaultSource;
}
else
{
throw new ApplicationException("Default push source configuration is not set. Please pass a source to push to, such as --source={0}".format_with(ApplicationParameters.ChocolateyCommunityFeedPushSource));
}
}

if (string.IsNullOrWhiteSpace(configuration.Sources))
{
configuration.Sources = ApplicationParameters.ChocolateyCommunityFeedPushSource;
}

if (!string.IsNullOrWhiteSpace(configuration.Sources))
Expand Down

0 comments on commit cacb4ed

Please sign in to comment.