Skip to content

Commit

Permalink
(chocolatey#62) Add unit tests for DefaultPushSource
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheCakeIsNaOH committed Oct 29, 2021
1 parent 7982238 commit 96abeab
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<ApplicationException>();
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
Expand Down

0 comments on commit 96abeab

Please sign in to comment.