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
|
|
@ -138,8 +138,15 @@ public class GitManager
|
||||||
// we add it to the relevant dictionary
|
// we add it to the relevant dictionary
|
||||||
if (directorySegmentsFromName.Count == 0)
|
if (directorySegmentsFromName.Count == 0)
|
||||||
{
|
{
|
||||||
FullRepositoryPath = absoluteRepositoryLocation;
|
// If this is a new registration, set the FullRepositoryPath and return, otherwise we've got a duplicate
|
||||||
return this;
|
// entry and we throw
|
||||||
|
if (FullRepositoryPath == null)
|
||||||
|
{
|
||||||
|
FullRepositoryPath = absoluteRepositoryLocation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception($"Registration already exists for {InternalPath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextSegment = directorySegmentsFromName.Peek();
|
var nextSegment = directorySegmentsFromName.Peek();
|
||||||
|
|
|
||||||
|
|
@ -74,4 +74,23 @@ public class AddRegistrationTests
|
||||||
|
|
||||||
Assert.Equal("repo", whitespaceName);
|
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