forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi-target netstandard2.0 and net461.
Unit test projects have to stay on net461 for now due to some of the libraries they consume. Bring GitTools.Core and GitTools.Testing directly into this repository. Update LibGit2Sharp and LibGit2Sharp.NativeBinaries Set new build scripts to use net461 Consolidate versions of some unit testing related nuget packages.
- Loading branch information
Showing
80 changed files
with
7,539 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<PackageVersion_GitToolsCore>1.3.1</PackageVersion_GitToolsCore> | ||
<PackageVersion_YamlDotNet>5.2.1</PackageVersion_YamlDotNet> | ||
<PackageVersion_LibGit2SharpNativeBinaries>[1.0.185]</PackageVersion_LibGit2SharpNativeBinaries> | ||
<PackageVersion_LibGit2Sharp>0.26.0-preview-0070</PackageVersion_LibGit2Sharp> | ||
<PackageVersion_LibGit2SharpNativeBinaries>[1.0.258]</PackageVersion_LibGit2SharpNativeBinaries> | ||
</PropertyGroup> | ||
</Project> |
325 changes: 325 additions & 0 deletions
325
src/GitTools.Core.Tests/Git/DynamicRepositoriesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,325 @@ | ||
namespace GitTools.Tests.Git | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using GitTools.Git; | ||
using IO; | ||
using LibGit2Sharp; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using Testing; | ||
|
||
[TestFixture] | ||
public class DynamicRepositoriesTests | ||
{ | ||
const string DefaultBranchName = "master"; | ||
const string SpecificBranchName = "feature/foo"; | ||
|
||
[Test] | ||
[TestCase(DefaultBranchName, DefaultBranchName)] | ||
[TestCase(SpecificBranchName, SpecificBranchName)] | ||
[Category("NoMono")] | ||
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName) | ||
{ | ||
var repoName = Guid.NewGuid().ToString(); | ||
var tempPath = Path.GetTempPath(); | ||
var tempDir = Path.Combine(tempPath, repoName); | ||
Directory.CreateDirectory(tempDir); | ||
string dynamicRepositoryPath = null; | ||
|
||
try | ||
{ | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last()); | ||
|
||
fixture.Repository.MakeCommits(5); | ||
fixture.Repository.CreateFileAndCommit("TestFile.txt"); | ||
|
||
var branch = fixture.Repository.CreateBranch(SpecificBranchName); | ||
|
||
// Copy contents into working directory | ||
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt")); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = fixture.RepositoryPath | ||
}; | ||
|
||
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, branchName, branch.Tip.Sha)) | ||
{ | ||
dynamicRepositoryPath = dynamicRepository.Repository.Info.Path; | ||
dynamicRepository.Repository.Info.Path.ShouldBe(Path.Combine(expectedDynamicRepoLocation, ".git\\")); | ||
|
||
var currentBranch = dynamicRepository.Repository.Head.CanonicalName; | ||
|
||
currentBranch.ShouldEndWith(expectedBranchName); | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
Directory.Delete(tempDir, true); | ||
|
||
if (dynamicRepositoryPath != null) | ||
{ | ||
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void UpdatesExistingDynamicRepository() | ||
{ | ||
var repoName = Guid.NewGuid().ToString(); | ||
var tempPath = Path.GetTempPath(); | ||
var tempDir = Path.Combine(tempPath, repoName); | ||
Directory.CreateDirectory(tempDir); | ||
string dynamicRepositoryPath = null; | ||
|
||
try | ||
{ | ||
using (var mainRepositoryFixture = new EmptyRepositoryFixture()) | ||
{ | ||
var commit = mainRepositoryFixture.Repository.MakeACommit(); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = mainRepositoryFixture.RepositoryPath | ||
}; | ||
|
||
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", commit.Sha)) | ||
{ | ||
dynamicRepositoryPath = dynamicRepository.Repository.Info.Path; | ||
} | ||
|
||
var newCommit = mainRepositoryFixture.Repository.MakeACommit(); | ||
|
||
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", newCommit.Sha)) | ||
{ | ||
dynamicRepository.Repository.Info.Path.ShouldBe(dynamicRepositoryPath); | ||
dynamicRepository.Repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha); | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
Directory.Delete(tempDir, true); | ||
|
||
if (dynamicRepositoryPath != null) | ||
{ | ||
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("NoMono")] | ||
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken() | ||
{ | ||
var repoName = Guid.NewGuid().ToString(); | ||
var tempPath = Path.GetTempPath(); | ||
var tempDir = Path.Combine(tempPath, repoName); | ||
Directory.CreateDirectory(tempDir); | ||
string expectedDynamicRepoLocation = null; | ||
|
||
try | ||
{ | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
var head = fixture.Repository.CreateFileAndCommit("TestFile.txt"); | ||
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt")); | ||
expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split(Path.DirectorySeparatorChar).Last()); | ||
Directory.CreateDirectory(expectedDynamicRepoLocation); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = fixture.RepositoryPath | ||
}; | ||
|
||
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha)) | ||
{ | ||
dynamicRepository.Repository.Info.Path.ShouldBe(Path.Combine(expectedDynamicRepoLocation + "_1", ".git\\")); | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
DeleteHelper.DeleteDirectory(tempDir, true); | ||
if (expectedDynamicRepoLocation != null) | ||
{ | ||
DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true); | ||
} | ||
|
||
if (expectedDynamicRepoLocation != null) | ||
{ | ||
DeleteHelper.DeleteGitRepository(expectedDynamicRepoLocation + "_1"); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
[Category("NoMono")] | ||
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderIsInUse() | ||
{ | ||
var tempPath = Path.GetTempPath(); | ||
var expectedDynamicRepoLocation = default(string); | ||
var expectedDynamicRepo2Location = default(string); | ||
|
||
try | ||
{ | ||
using (var fixture = new EmptyRepositoryFixture()) | ||
{ | ||
var head = fixture.Repository.CreateFileAndCommit("TestFile.txt"); | ||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = fixture.RepositoryPath | ||
}; | ||
|
||
using (var dynamicRepository = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha)) | ||
using (var dynamicRepository2 = DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", head.Sha)) | ||
{ | ||
expectedDynamicRepoLocation = dynamicRepository.Repository.Info.Path; | ||
expectedDynamicRepo2Location = dynamicRepository2.Repository.Info.Path; | ||
dynamicRepository.Repository.Info.Path.ShouldNotBe(dynamicRepository2.Repository.Info.Path); | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
if (expectedDynamicRepoLocation != null) | ||
{ | ||
DeleteHelper.DeleteDirectory(expectedDynamicRepoLocation, true); | ||
} | ||
|
||
if (expectedDynamicRepo2Location != null) | ||
{ | ||
DeleteHelper.DeleteGitRepository(expectedDynamicRepo2Location); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void ThrowsExceptionWhenNotEnoughInfo() | ||
{ | ||
var tempDir = Path.GetTempPath(); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = tempDir | ||
}; | ||
|
||
Should.Throw<Exception>(() => DynamicRepositories.CreateOrOpen(repositoryInfo, tempDir, null, null)); | ||
} | ||
|
||
[Test] | ||
public void UsingDynamicRepositoryWithFeatureBranchWorks() | ||
{ | ||
var repoName = Guid.NewGuid().ToString(); | ||
var tempPath = Path.GetTempPath(); | ||
var tempDir = Path.Combine(tempPath, repoName); | ||
Directory.CreateDirectory(tempDir); | ||
|
||
try | ||
{ | ||
using (var mainRepositoryFixture = new EmptyRepositoryFixture()) | ||
{ | ||
var commit = mainRepositoryFixture.Repository.MakeACommit(); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = mainRepositoryFixture.RepositoryPath | ||
}; | ||
|
||
Commands.Checkout(mainRepositoryFixture.Repository, mainRepositoryFixture.Repository.CreateBranch("feature1")); | ||
|
||
Should.NotThrow(() => | ||
{ | ||
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "feature1", commit.Sha)) | ||
{ | ||
} | ||
}); | ||
} | ||
} | ||
finally | ||
{ | ||
Directory.Delete(tempDir, true); | ||
} | ||
} | ||
|
||
[Test] | ||
public void UsingDynamicRepositoryWithoutTargetBranchFails() | ||
{ | ||
var tempPath = Path.GetTempPath(); | ||
|
||
using (var mainRepositoryFixture = new EmptyRepositoryFixture()) | ||
{ | ||
mainRepositoryFixture.Repository.MakeACommit(); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = mainRepositoryFixture.RepositoryPath | ||
}; | ||
|
||
Should.Throw<GitToolsException>(() => | ||
{ | ||
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, null, null)) | ||
{ | ||
} | ||
}); | ||
} | ||
} | ||
|
||
[Test] | ||
public void UsingDynamicRepositoryWithoutTargetBranchCommitFails() | ||
{ | ||
var tempPath = Path.GetTempPath(); | ||
|
||
using (var mainRepositoryFixture = new EmptyRepositoryFixture()) | ||
{ | ||
mainRepositoryFixture.Repository.MakeACommit(); | ||
|
||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = mainRepositoryFixture.RepositoryPath | ||
}; | ||
|
||
Should.Throw<GitToolsException>(() => | ||
{ | ||
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", null)) | ||
{ | ||
} | ||
}); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestErrorThrownForInvalidRepository() | ||
{ | ||
var repoName = Guid.NewGuid().ToString(); | ||
var tempPath = Path.GetTempPath(); | ||
var tempDir = Path.Combine(tempPath, repoName); | ||
Directory.CreateDirectory(tempDir); | ||
|
||
try | ||
{ | ||
var repositoryInfo = new RepositoryInfo | ||
{ | ||
Url = "http://127.0.0.1/testrepo.git" | ||
}; | ||
|
||
Should.Throw<Exception>(() => | ||
{ | ||
using (DynamicRepositories.CreateOrOpen(repositoryInfo, tempPath, "master", "sha")) | ||
{ | ||
} | ||
}); | ||
} | ||
finally | ||
{ | ||
Directory.Delete(tempDir, true); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.