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.
(GitToolsGH-2456) Add test to cover code change
Without the code change, this test fails with an incorrectly asserted version number, similar to 0.3.0-tags-01, when it should be 0.2.0.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using GitTools.Testing; | ||
using GitVersion.BuildAgents; | ||
using GitVersion.Core.Tests.Helpers; | ||
using LibGit2Sharp; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
|
||
namespace GitVersion.App.Tests | ||
{ | ||
[TestFixture] | ||
public class TagCheckoutInBuildAgentTests | ||
{ | ||
[Test] | ||
public async Task VerifyTagCheckoutOnGitHubActions() | ||
{ | ||
var env = new Dictionary<string, string> | ||
{ | ||
{ GitHubActions.EnvironmentVariableName, "true" }, | ||
{ "GITHUB_REF", "ref/tags/0.2.0" }, | ||
}; | ||
|
||
using var fixture = new EmptyRepositoryFixture(); | ||
var remoteRepositoryPath = PathHelper.GetTempPath(); | ||
RepositoryFixtureBase.Init(remoteRepositoryPath); | ||
using (var remoteRepository = new Repository(remoteRepositoryPath)) | ||
{ | ||
remoteRepository.Config.Set("user.name", "Test"); | ||
remoteRepository.Config.Set("user.email", "[email protected]"); | ||
fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath); | ||
Console.WriteLine("Created git repository at {0}", remoteRepositoryPath); | ||
remoteRepository.MakeATaggedCommit("0.1.0"); | ||
Commands.Checkout(remoteRepository, remoteRepository.CreateBranch("develop")); | ||
remoteRepository.MakeACommit(); | ||
Commands.Checkout(remoteRepository, remoteRepository.CreateBranch("release/0.2.0")); | ||
remoteRepository.MakeACommit(); | ||
Commands.Checkout(remoteRepository, "main"); | ||
remoteRepository.MergeNoFF("release/0.2.0", Generate.SignatureNow()); | ||
remoteRepository.MakeATaggedCommit("0.2.0"); | ||
|
||
Commands.Fetch((Repository)fixture.Repository, "origin", new string[0], new FetchOptions(), null); | ||
Commands.Checkout(fixture.Repository, "0.2.0"); | ||
} | ||
|
||
var programFixture = new ProgramFixture(fixture.RepositoryPath); | ||
programFixture.WithEnv(env.ToArray()); | ||
|
||
var result = await programFixture.Run(); | ||
|
||
result.ExitCode.ShouldBe(0); | ||
result.OutputVariables.FullSemVer.ShouldBe("0.2.0"); | ||
|
||
// Cleanup repository files | ||
DirectoryHelper.DeleteDirectory(remoteRepositoryPath); | ||
} | ||
} | ||
} |