Skip to content

Commit 5d447c6

Browse files
committed
WIP test of git vcs provider
1 parent 8d5dacf commit 5d447c6

File tree

5 files changed

+86
-34
lines changed

5 files changed

+86
-34
lines changed

src/Vcs/Git/GitVcs.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.IO;
34

45
namespace Skarp.Version.Cli.Vcs.Git
56
{
@@ -54,14 +55,17 @@ public void Tag(string tagName)
5455
}
5556
}
5657

57-
private static bool LaunchGitWithArgs(string args, int waitForExitTimeMs = 1000, int exitCode = 0)
58+
internal static bool LaunchGitWithArgs(string args, int waitForExitTimeMs = 1000, int exitCode = 0)
5859
{
5960
try
6061
{
6162
var startInfo = CreateGitShellStartInfo(args);
6263
var proc = Process.Start(startInfo);
6364
proc.WaitForExit(waitForExitTimeMs);
6465

66+
var stdOut = proc.StandardOutput.ReadToEnd();
67+
var stdErr = proc.StandardError.ReadToEnd();
68+
6569
return proc.ExitCode == exitCode;
6670
}
6771
catch (Exception ex)
@@ -70,8 +74,7 @@ private static bool LaunchGitWithArgs(string args, int waitForExitTimeMs = 1000,
7074
return false;
7175
}
7276
}
73-
74-
private static ProcessStartInfo CreateGitShellStartInfo(string args)
77+
internal static ProcessStartInfo CreateGitShellStartInfo(string args)
7578
{
7679
return new ProcessStartInfo("git")
7780
{

test/GitVcsTest.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/Vcs/Git/GitVcsTest.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Skarp.Version.Cli.Vcs.Git;
2+
using Xunit;
3+
4+
namespace Skarp.Version.Cli.Test
5+
{
6+
public class GitVcsTest : IClassFixture<GitVcsFixture>
7+
{
8+
private readonly GitVcsFixture _fixture;
9+
10+
11+
public GitVcsTest(GitVcsFixture fixture)
12+
{
13+
_fixture = fixture;
14+
}
15+
16+
[Fact]
17+
public void DetectingGitOnMachineWorks()
18+
{
19+
Assert.True(_fixture.Vcs.IsVcsToolPresent());
20+
}
21+
22+
[Fact]
23+
public void IsRepositoryCleanWorks()
24+
{
25+
Assert.True(_fixture.Vcs.IsRepositoryClean());
26+
}
27+
}
28+
}

test/Vcs/Git/GitVcsTestFixture.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.IO;
3+
using System.IO.Compression;
4+
using Skarp.Version.Cli.Vcs.Git;
5+
6+
namespace Skarp.Version.Cli.Test
7+
{
8+
public class GitVcsFixture : IDisposable
9+
{
10+
public readonly string GitTestDir;
11+
public readonly GitVcs Vcs;
12+
13+
public GitVcsFixture()
14+
{
15+
GitTestDir = "./target-git-dir";
16+
DirectoryDelete(GitTestDir, recursive: true);
17+
18+
ZipFile.ExtractToDirectory("./target-git.zip", "./");
19+
Vcs = new GitVcs();
20+
21+
Directory.SetCurrentDirectory(
22+
Path.Combine(
23+
Directory.GetCurrentDirectory(),
24+
GitTestDir
25+
)
26+
);
27+
}
28+
29+
private void DirectoryDelete(string dir, bool recursive)
30+
{
31+
try
32+
{
33+
Directory.Delete(dir, recursive);
34+
}
35+
// we don't want to fail at all if deleting the dir fails
36+
catch (Exception ex)
37+
{
38+
}
39+
}
40+
41+
public void Dispose()
42+
{
43+
Directory.SetCurrentDirectory(
44+
Path.Combine(
45+
Directory.GetCurrentDirectory(),
46+
"../"
47+
)
48+
);
49+
DirectoryDelete(GitTestDir, recursive: true);
50+
}
51+
}
52+
}

test/target-git.zip

18.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)