-
Notifications
You must be signed in to change notification settings - Fork 652
/
Copy pathGitPreparerTests.cs
71 lines (58 loc) · 2.14 KB
/
GitPreparerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace GitVersionExe.Tests
{
using System.IO;
using GitVersion;
using LibGit2Sharp;
using NUnit.Framework;
[TestFixture]
public class GitPreparerTests
{
public GitPreparerTests()
{
Logger.WriteInfo = s => { };
Logger.WriteWarning = s => { };
Logger.WriteError = s => { };
}
const string RemoteRepositoryUrl = "https://github.com/ParticularLabs/GitVersion.git";
const string DefaultBranchName = "master";
const string SpecificBranchName = "gh-pages";
[Explicit]
[TestCase(null, DefaultBranchName)]
[TestCase(SpecificBranchName, SpecificBranchName)]
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName)
{
var tempDir = Path.GetTempPath();
var arguments = new Arguments
{
TargetPath = tempDir,
TargetUrl = RemoteRepositoryUrl
};
if (!string.IsNullOrWhiteSpace(branchName))
{
arguments.TargetBranch = branchName;
}
var gitPreparer = new GitPreparer(arguments);
var dynamicRepositoryPath = gitPreparer.Prepare();
Assert.AreEqual(Path.Combine(tempDir, "_dynamicrepository", ".git"), dynamicRepositoryPath);
Assert.IsTrue(gitPreparer.IsDynamicGitRepository);
using (var repository = new Repository(dynamicRepositoryPath))
{
var currentBranch = repository.Head.CanonicalName;
Assert.IsTrue(currentBranch.EndsWith(expectedBranchName));
}
}
[Test]
public void WorksCorrectlyWithLocalRepository()
{
var tempDir = Path.GetTempPath();
var arguments = new Arguments
{
TargetPath = tempDir
};
var gitPreparer = new GitPreparer(arguments);
var dynamicRepositoryPath = gitPreparer.Prepare();
Assert.AreEqual(null, dynamicRepositoryPath);
Assert.IsFalse(gitPreparer.IsDynamicGitRepository);
}
}
}