tests(git-provider): Add duplicated repo registration test
This commit is contained in:
parent
cf2660b6b2
commit
30e103f021
2 changed files with 28 additions and 2 deletions
|
|
@ -137,11 +137,18 @@ public class GitManager
|
|||
// We're at the end of the directory segments so we can safely say we're at the end of the tree so
|
||||
// we add it to the relevant dictionary
|
||||
if (directorySegmentsFromName.Count == 0)
|
||||
{
|
||||
// If this is a new registration, set the FullRepositoryPath and return, otherwise we've got a duplicate
|
||||
// entry and we throw
|
||||
if (FullRepositoryPath == null)
|
||||
{
|
||||
FullRepositoryPath = absoluteRepositoryLocation;
|
||||
return this;
|
||||
}
|
||||
|
||||
throw new Exception($"Registration already exists for {InternalPath}");
|
||||
}
|
||||
|
||||
var nextSegment = directorySegmentsFromName.Peek();
|
||||
|
||||
// Attempt to get the next level of the directory. If we don't have a key entry, create one
|
||||
|
|
|
|||
|
|
@ -74,4 +74,23 @@ public class AddRegistrationTests
|
|||
|
||||
Assert.Equal("repo", whitespaceName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DuplicateRepoRegistrationShouldFail()
|
||||
{
|
||||
Settings.UseFileName(nameof(RepoRegistrationWithWhitespaceName));
|
||||
|
||||
var gitManager = GitManager.InternalFreshInstance;
|
||||
var testRepoAbsolutePath = "Test:/some/test/repo";
|
||||
string[] paths = ["test", "nested", "path"];
|
||||
var names = (NormalSeparator: string.Join(Path.DirectorySeparatorChar, paths), AltSeparator: string.Join(Path.AltDirectorySeparatorChar, paths));
|
||||
|
||||
var firstRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, names.NormalSeparator);
|
||||
// TODO: make nested registrations fail in both directions and test
|
||||
var secondRegistration = gitManager.RegisterRepo(testRepoAbsolutePath, Path.Combine(paths[..1]));
|
||||
|
||||
Assert.Equal(Path.Combine(paths), firstRegistration);
|
||||
|
||||
Assert.Throws<Exception>(() => gitManager.RegisterRepo(testRepoAbsolutePath, names.AltSeparator));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue