Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 9d4235a

Browse files
committed
Add test for empty directory on clone fail.
1 parent b42e08e commit 9d4235a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

test/GitHub.App.UnitTests/Services/RepositoryCloneServiceTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ await usageTracker.Received(numberOfCalls).IncrementCounter(
122122
((MemberExpression)x.Body).Member.Name == counterName));
123123
}
124124

125+
[Test]
126+
public async Task CleansDirectoryOnCloneFailed()
127+
{
128+
var serviceProvider = Substitutes.GetServiceProvider();
129+
var operatingSystem = serviceProvider.GetOperatingSystem();
130+
var vsGitServices = serviceProvider.GetVSGitServices();
131+
var cloneService = CreateRepositoryCloneService(serviceProvider);
132+
133+
Assert.ThrowsAsync<Exception>(async () => {
134+
await cloneService.CloneRepository("https://github.com/failing/url", @"c:\dev\bar");
135+
});
136+
137+
operatingSystem.Directory.Received().CreateDirectory(@"c:\dev\bar");
138+
operatingSystem.Directory.Received().DeleteDirectory(@"c:\dev\bar");
139+
await vsGitServices.Received().Clone("https://github.com/failing/url", @"c:\dev\bar", true);
140+
}
141+
125142
static RepositoryCloneService CreateRepositoryCloneService(IGitHubServiceProvider sp)
126143
{
127144
return new RepositoryCloneService(sp.GetOperatingSystem(), sp.GetVSGitServices(), sp.GetTeamExplorerServices(),

test/GitHub.App.UnitTests/Substitutes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static IVSGitServices IVSGitServices
4040
{
4141
var ret = Substitute.For<IVSGitServices>();
4242
ret.GetLocalClonePathFromGitProvider().Returns(@"c:\foo\bar");
43+
ret.Clone("https://github.com/failing/url", @"c:\dev\bar", true).Returns(x => { throw new Exception(); });
4344
return ret;
4445
}
4546
}

0 commit comments

Comments
 (0)