Skip to content

Commit b2d676e

Browse files
committed
add failing unit test
1 parent f36f6ea commit b2d676e

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"Major": 5,
3+
"Minor": 0,
4+
"Patch": 0,
5+
"PreReleaseTag": {
6+
"Name": "beta",
7+
"Number": 2
8+
},
9+
"BuildMetaData": {
10+
"CommitsSinceTag": 1,
11+
"Branch": "release-5.0.0",
12+
"ReleaseDate": {
13+
"OriginalDate": "<date replaced>",
14+
"OriginalCommitSha": "000000000000000000000000000000000000000",
15+
"Date": "<date replaced>",
16+
"CommitSha": "000000000000000000000000000000000000000"
17+
},
18+
"Sha": "000000000000000000000000000000000000000",
19+
"OtherMetaData": null
20+
}
21+
}

Tests/BranchFinders/ReleaseTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GitVersion;
22
using LibGit2Sharp;
33
using NUnit.Framework;
4+
using ObjectApproval;
45

56
[TestFixture]
67
public class ReleaseTests : Lg2sHelperBase
@@ -39,4 +40,22 @@ public void EnsureAReleaseBranchNameDoesNotExposeAStability()
3940
}
4041
}
4142

43+
[Test]
44+
public void Tag_on_commit_should_be_exact_tag()
45+
{
46+
var repoPath = Clone(ASBMTestRepoWorkingDirPath);
47+
using (var repo = new Repository(repoPath))
48+
{
49+
// Create a release branch from the parent of current develop tip
50+
repo.Branches.Add("release-5.0.0", "develop~").ForceCheckout();
51+
52+
AddOneCommitToHead(repo, "code");
53+
AddTag(repo, "5.0.0-beta2");
54+
55+
var finder = new ReleaseVersionFinder();
56+
57+
var version = finder.FindVersion(new GitVersionContext(repo, repo.Head));
58+
ObjectApprover.VerifyWithJson(version, Scrubbers.GuidAndDateScrubber);
59+
}
60+
}
4261
}

Tests/Helpers/Lg2sHelperBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ protected static Commit AddOneCommitToHead(Repository repo, string type)
105105
var sign = Constants.SignatureNow();
106106
return repo.Commit(type + " commit", sign, sign);
107107
}
108+
protected static void AddTag(Repository repo, string tagName)
109+
{
110+
var randomFile = Path.Combine(repo.Info.WorkingDirectory, Guid.NewGuid().ToString());
111+
File.WriteAllText(randomFile, string.Empty);
112+
repo.Index.Stage(randomFile);
113+
var sign = Constants.SignatureNow();
114+
repo.ApplyTag(tagName, sign, "foo");
115+
}
108116
}

0 commit comments

Comments
 (0)