Skip to content

Commit e22e66b

Browse files
asbjornuJakeGinnivan
authored andcommitted
Rewrote the VersionAndBranchFinder tests so they do actual file system work, since AppVeyor don't seem to agree with local test running in that everything is green. Not trying to fake it may be a better solution anyhow.
Ref https://ci.appveyor.com/project/GitTools/gitversion/build/3.3.1-PullRequest.711+28%20(Build%20458)
1 parent 5a4b29b commit e22e66b

File tree

1 file changed

+87
-10
lines changed

1 file changed

+87
-10
lines changed

src/GitVersionTask.Tests/VersionAndBranchFinderTests.cs

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
#endregion
1111

12+
using System;
13+
using System.Collections.Concurrent;
14+
using System.Text;
15+
16+
using GitVersion;
17+
using GitVersion.Helpers;
18+
1219
using NUnit.Framework;
1320

1421
using Shouldly;
@@ -17,10 +24,9 @@
1724
public class VersionAndBranchFinderTests
1825
{
1926
[Test]
20-
public void ExistingCacheFile()
27+
public void CacheFileExistsOnDisk()
2128
{
22-
var fileSystem = new TestFileSystem();
23-
fileSystem.WriteAllText("existing\\gitversion_cache\\C7B23F8A47ECE0E14CBE2E22C04269CC5A88E275.yml", @"
29+
const string versionCacheFileContent = @"
2430
Major: 4
2531
Minor: 10
2632
Patch: 3
@@ -43,21 +49,92 @@ public void ExistingCacheFile()
4349
CommitsSinceVersionSource: 19
4450
CommitsSinceVersionSourcePadded: 0019
4551
CommitDate: 2015-11-10
46-
");
52+
";
53+
54+
var infoBuilder = new StringBuilder();
55+
Action<string> infoLogger = s => { infoBuilder.AppendLine(s); };
56+
57+
Logger.SetLoggers(infoLogger, null, null);
58+
59+
using (var fixture = new EmptyRepositoryFixture(new Config()))
60+
{
61+
var fileSystem = new FileSystem();
62+
fixture.Repository.MakeACommit();
63+
var vv = VersionAndBranchFinder.GetVersion(fixture.RepositoryPath, null, false, fileSystem);
64+
65+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
66+
67+
vv.FileName.ShouldNotBeNullOrEmpty();
68+
69+
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
70+
71+
// I would rather see that VersionAndBranchFinder was non-static and could be reinstantiated to
72+
// clear the in-memory cache, but that's not the case, so I have to perform this ugly hack. @asbjornu
73+
VersionAndBranchFinder.VersionCacheVersions = new ConcurrentDictionary<string, VersionVariables>();
74+
75+
vv = VersionAndBranchFinder.GetVersion(fixture.RepositoryPath, null, false, fileSystem);
76+
77+
vv.AssemblySemVer.ShouldBe("4.10.3.0");
78+
}
79+
80+
var info = infoBuilder.ToString();
81+
82+
Console.WriteLine(info);
83+
84+
info.ShouldContain("Deserializing version variables from cache file", () => info);
85+
}
86+
87+
88+
[Test]
89+
public void CacheFileExistsInMemory()
90+
{
91+
var infoBuilder = new StringBuilder();
92+
Action<string> infoLogger = s => { infoBuilder.AppendLine(s); };
93+
94+
Logger.SetLoggers(infoLogger, null, null);
95+
96+
using (var fixture = new EmptyRepositoryFixture(new Config()))
97+
{
98+
var fileSystem = new FileSystem();
99+
fixture.Repository.MakeACommit();
100+
var vv = VersionAndBranchFinder.GetVersion(fixture.RepositoryPath, null, false, fileSystem);
47101

48-
var vv = VersionAndBranchFinder.GetVersion("existing", null, false, fileSystem);
102+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
49103

50-
vv.AssemblySemVer.ShouldBe("4.10.3.0");
104+
vv.FileName.ShouldNotBeNullOrEmpty();
105+
106+
vv = VersionAndBranchFinder.GetVersion(fixture.RepositoryPath, null, false, fileSystem);
107+
108+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
109+
}
110+
111+
var info = infoBuilder.ToString();
112+
113+
Console.WriteLine(info);
114+
115+
info.ShouldContain("yml not found", () => info);
116+
info.ShouldNotContain("Deserializing version variables from cache file", () => info);
51117
}
52118

53119

54120
[Test]
55-
public void MissingCacheFile()
121+
public void CacheFileIsMissing()
56122
{
57-
var fileSystem = new TestFileSystem();
123+
var infoBuilder = new StringBuilder();
124+
Action<string> infoLogger = s => { infoBuilder.AppendLine(s); };
125+
126+
Logger.SetLoggers(infoLogger, null, null);
127+
128+
using (var fixture = new EmptyRepositoryFixture(new Config()))
129+
{
130+
fixture.Repository.MakeACommit();
131+
var fileSystem = new FileSystem();
132+
var vv = VersionAndBranchFinder.GetVersion(fixture.RepositoryPath, null, false, fileSystem);
58133

59-
var vv = VersionAndBranchFinder.GetVersion("missing", null, false, fileSystem);
134+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
135+
}
60136

61-
vv.AssemblySemVer.ShouldBe("0.1.0.0");
137+
var info = infoBuilder.ToString();
138+
info.ShouldContain("yml not found", () => info);
62139
}
63140
}

0 commit comments

Comments
 (0)