Skip to content

Commit 165456f

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 6c891b7 commit 165456f

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
@@ -452,19 +452,35 @@ public void CanSetAndGetMultipleSearchPaths()
452452
[Fact]
453453
public void CanResetSearchPaths()
454454
{
455-
// set the global search path to its default value
455+
// all of these calls should reset the config path to the default
456+
Action[] resetActions =
457+
{
458+
() => GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global),
459+
() => GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null),
460+
() => GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, string.Empty),
461+
};
462+
463+
// record the default search path
456464
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
457465
var oldPaths = GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global);
458466
Assert.NotNull(oldPaths);
459467

460-
// change to something other than the default
468+
// generate a non-default path to set
461469
var newPaths = new string[] { Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName()) };
462-
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, newPaths);
463-
Assert.Equal(newPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
464470

465-
// set it back to the default
471+
foreach (var tryToReset in resetActions)
472+
{
473+
// change to the non-default path
474+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, newPaths);
475+
Assert.Equal(newPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
476+
477+
// set it back to the default
478+
tryToReset();
479+
Assert.Equal(oldPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
480+
}
481+
482+
// make sure the config paths are reset after the test ends
466483
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
467-
Assert.Equal(oldPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
468484
}
469485

470486
[Fact]

0 commit comments

Comments
 (0)