Skip to content

Commit

Permalink
(GH-2456) Add test to cover code change
Browse files Browse the repository at this point in the history
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
gep13 authored and arturcic committed Feb 6, 2021
1 parent d20b537 commit 83d172f
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/GitVersion.App.Tests/TagCheckoutInBuildAgentTests.cs
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, TestBase.MainBranch);
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);
}
}
}

0 comments on commit 83d172f

Please sign in to comment.