-
Notifications
You must be signed in to change notification settings - Fork 654
Cache version information to disk #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
659cff4
c20abdb
fbc0d87
242a074
b54d7f4
c2766ec
fe29d11
5259594
407a9e3
5e4532e
c16acbc
a37d211
41bb6eb
6a0fa0f
b1e41fa
a5d425b
82a1346
56b9b2d
6638e89
0114126
216c044
ed5edd6
5000e3c
1c2c273
ba89853
7b5e3c5
817729d
c6943e6
f7f95c2
5dd4d3f
207cc67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Text; | ||
|
||
using GitVersion; | ||
using GitVersion.Helpers; | ||
|
||
using NUnit.Framework; | ||
|
||
using Shouldly; | ||
|
||
[TestFixture] | ||
public class ExecuteCoreTests | ||
{ | ||
IFileSystem fileSystem; | ||
|
||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
this.fileSystem = new FileSystem(); | ||
} | ||
|
||
|
||
[Test] | ||
public void CacheFileExistsOnDisk() | ||
{ | ||
const string versionCacheFileContent = @" | ||
Major: 4 | ||
Minor: 10 | ||
Patch: 3 | ||
PreReleaseTag: test.19 | ||
PreReleaseTagWithDash: -test.19 | ||
BuildMetaData: | ||
BuildMetaDataPadded: | ||
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f | ||
MajorMinorPatch: 4.10.3 | ||
SemVer: 4.10.3-test.19 | ||
LegacySemVer: 4.10.3-test19 | ||
LegacySemVerPadded: 4.10.3-test0019 | ||
AssemblySemVer: 4.10.3.0 | ||
FullSemVer: 4.10.3-test.19 | ||
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f | ||
BranchName: feature/test | ||
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f | ||
NuGetVersionV2: 4.10.3-test0019 | ||
NuGetVersion: 4.10.3-test0019 | ||
CommitsSinceVersionSource: 19 | ||
CommitsSinceVersionSourcePadded: 0019 | ||
CommitDate: 2015-11-10 | ||
"; | ||
|
||
var versionAndBranchFinder = new ExecuteCore(this.fileSystem); | ||
|
||
var info = RepositoryScope(versionAndBranchFinder, (fixture, vv) => | ||
{ | ||
this.fileSystem.WriteAllText(vv.FileName, versionCacheFileContent); | ||
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); | ||
vv.AssemblySemVer.ShouldBe("4.10.3.0"); | ||
}); | ||
|
||
info.ShouldContain("Deserializing version variables from cache file", () => info); | ||
} | ||
|
||
|
||
[Test] | ||
public void CacheFileExistsInMemory() | ||
{ | ||
var cache = new ConcurrentDictionary<string, VersionVariables>(); | ||
var versionAndBranchFinder = new ExecuteCore(this.fileSystem, cache.GetOrAdd); | ||
|
||
var info = RepositoryScope(versionAndBranchFinder, (fixture, vv) => | ||
{ | ||
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); | ||
vv.AssemblySemVer.ShouldBe("0.1.0.0"); | ||
}); | ||
|
||
info.ShouldContain("yml not found", () => info); | ||
info.ShouldNotContain("Deserializing version variables from cache file", () => info); | ||
} | ||
|
||
|
||
[Test] | ||
public void CacheFileIsMissing() | ||
{ | ||
var info = RepositoryScope(); | ||
info.ShouldContain("yml not found", () => info); | ||
} | ||
|
||
|
||
string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null) | ||
{ | ||
var infoBuilder = new StringBuilder(); | ||
Action<string> infoLogger = s => { infoBuilder.AppendLine(s); }; | ||
executeCore = executeCore ?? new ExecuteCore(this.fileSystem); | ||
|
||
Logger.SetLoggers(infoLogger, s => { }, s => { }); | ||
|
||
using (var fixture = new EmptyRepositoryFixture(new Config())) | ||
{ | ||
fixture.Repository.MakeACommit(); | ||
var vv = executeCore.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null); | ||
|
||
vv.AssemblySemVer.ShouldBe("0.1.0.0"); | ||
vv.FileName.ShouldNotBeNullOrEmpty(); | ||
|
||
if (fixtureAction != null) | ||
{ | ||
fixtureAction(fixture, vv); | ||
} | ||
} | ||
|
||
return infoBuilder.ToString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
using GitVersion.Helpers; | ||
|
||
using LibGit2Sharp; | ||
|
||
public class TestFileSystem : IFileSystem | ||
{ | ||
Dictionary<string, string> fileSystem = new Dictionary<string, string>(); | ||
|
||
|
||
public void Copy(string @from, string to, bool overwrite) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
public void Move(string @from, string to) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
public bool Exists(string file) | ||
{ | ||
return fileSystem.ContainsKey(file); | ||
return this.fileSystem.ContainsKey(file); | ||
} | ||
|
||
|
||
public void Delete(string path) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
public string ReadAllText(string path) | ||
{ | ||
return fileSystem[path]; | ||
return this.fileSystem[path]; | ||
} | ||
|
||
|
||
public void WriteAllText(string file, string fileContents) | ||
{ | ||
if (fileSystem.ContainsKey(file)) | ||
fileSystem[file] = fileContents; | ||
if (this.fileSystem.ContainsKey(file)) | ||
{ | ||
this.fileSystem[file] = fileContents; | ||
} | ||
else | ||
fileSystem.Add(file, fileContents); | ||
{ | ||
this.fileSystem.Add(file, fileContents); | ||
} | ||
} | ||
|
||
|
||
public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
public Stream OpenWrite(string path) | ||
{ | ||
return new TestStream(path, this); | ||
} | ||
|
||
|
||
public Stream OpenRead(string path) | ||
{ | ||
if (this.fileSystem.ContainsKey(path)) | ||
{ | ||
var content = this.fileSystem[path]; | ||
return new MemoryStream(Encoding.UTF8.GetBytes(content)); | ||
} | ||
|
||
throw new FileNotFoundException("File not found.", path); | ||
} | ||
|
||
|
||
public void CreateDirectory(string path) | ||
{ | ||
} | ||
|
||
|
||
public long GetLastDirectoryWrite(string path) | ||
{ | ||
return 1; | ||
} | ||
|
||
|
||
public IRepository GetRepository(string gitDirectory) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the Fixture stuff? Mocking out libgit2sharp stuff is annoying in the long run I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JakeGinnivan Yea, I ended up using the fixture stuff, which is why I ask what is causing the following exception:
Why are none of the other tests using the fixture having this problem? I see no mention of any remotes. |
||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GeertvanHorrik fyi. Maybe just make the file system stuff internal in Core. The needed abstractions will be different in each app
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I hoped the abstraction would be useful, but I ended up not using it. Mocking with
static
classes and methods is nigh impossible.