Skip to content

Commit 14dfe73

Browse files
author
Ryan Roden-Corrent
committed
Test SetConfigSearchPaths for empty string/array.
Adds testing to verify that passing an empty string or array to SetConfigSearchPaths should reset the search path to the default just as null does.
1 parent 633a021 commit 14dfe73

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,19 +474,35 @@ public void CanSetAndGetMultipleSearchPaths()
474474
[Fact]
475475
public void CanResetSearchPaths()
476476
{
477-
// set the global search path to its default value
477+
// all of these calls should reset the config path to the default
478+
Action[] resetActions =
479+
{
480+
() => GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global),
481+
() => GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null),
482+
() => GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, string.Empty),
483+
};
484+
485+
// record the default search path
478486
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
479487
var oldPaths = GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global);
480488
Assert.NotNull(oldPaths);
481489

482-
// change to something other than the default
490+
// generate a non-default path to set
483491
var newPaths = new string[] { Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName()) };
484-
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, newPaths);
485-
Assert.Equal(newPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
486492

487-
// set it back to the default
493+
foreach (var tryToReset in resetActions)
494+
{
495+
// change to the non-default path
496+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, newPaths);
497+
Assert.Equal(newPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
498+
499+
// set it back to the default
500+
tryToReset();
501+
Assert.Equal(oldPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
502+
}
503+
504+
// make sure the config paths are reset after the test ends
488505
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
489-
Assert.Equal(oldPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
490506
}
491507

492508
[Fact]

0 commit comments

Comments
 (0)