From 3a7ef21954e47ad874628f1c00583f34519ac5e4 Mon Sep 17 00:00:00 2001 From: Kieranties Date: Tue, 30 Apr 2019 12:01:11 +0100 Subject: [PATCH] chore: Test to validate overide configuration Fixes #71 --- .../Formatting/Semver1FormatProcess.cs | 7 +- .../Formatting/Semver2FormatProcess.cs | 7 +- .../EndToEndFixture.cs | 78 +++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 test/SimpleVersion.Core.Tests/EndToEndFixture.cs diff --git a/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs b/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs index f928c83..8dbdc35 100644 --- a/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/Formatting/Semver1FormatProcess.cs @@ -9,6 +9,11 @@ namespace SimpleVersion.Pipeline.Formatting /// public class Semver1FormatProcess : IVersionProcessor { + /// + /// The key used to identify this format. + /// + public const string FormatKey = "Semver1"; + /// public void Apply(VersionContext context) { @@ -29,7 +34,7 @@ public void Apply(VersionContext context) if (!string.IsNullOrWhiteSpace(label)) format += $"-{label}"; - context.Result.Formats["Semver1"] = format; + context.Result.Formats[FormatKey] = format; } } } diff --git a/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs b/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs index de35c2d..3576ee2 100644 --- a/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs +++ b/src/SimpleVersion.Core/Pipeline/Formatting/Semver2FormatProcess.cs @@ -9,6 +9,11 @@ namespace SimpleVersion.Pipeline.Formatting /// public class Semver2FormatProcess : IVersionProcessor { + /// + /// The key used to identify this format. + /// + public const string FormatKey = "Semver2"; + /// public void Apply(VersionContext context) { @@ -33,7 +38,7 @@ public void Apply(VersionContext context) if (!string.IsNullOrWhiteSpace(meta)) format += $"+{meta}"; - context.Result.Formats["Semver2"] = format; + context.Result.Formats[FormatKey] = format; } } } diff --git a/test/SimpleVersion.Core.Tests/EndToEndFixture.cs b/test/SimpleVersion.Core.Tests/EndToEndFixture.cs new file mode 100644 index 0000000..b33f9b6 --- /dev/null +++ b/test/SimpleVersion.Core.Tests/EndToEndFixture.cs @@ -0,0 +1,78 @@ +using FluentAssertions; +using GitTools.Testing; +using SimpleVersion.Pipeline; +using SimpleVersion.Pipeline.Formatting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace SimpleVersion.Core.Tests +{ +#pragma warning disable CA1063 // Implement IDisposable Correctly + public class EndToEndFixture : IDisposable +#pragma warning restore CA1063 // Implement IDisposable Correctly + { + private readonly EmptyRepositoryFixture _repo; + + public EndToEndFixture() + { + _repo = new EmptyRepositoryFixture(); + } + +#pragma warning disable CA1063 // Implement IDisposable Correctly +#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize + public void Dispose() => _repo?.Dispose(); +#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize +#pragma warning restore CA1063 // Implement IDisposable Correctly + + // https://github.com/Kieranties/SimpleVersion/issues/71 + [Fact] + public void Override_Branches_Do_Not_Work_If_Asterisk_Used_In_Label() + { + // Arrange + + // Create the configuration model + var config = new Model.Configuration + { + Version = "1.0.0", + Label = { "r*" }, + Branches = + { + Release = { "^refs/heads/master$", "^refs/heads/release/.+$", "^refs/heads/feature/.+$" }, + Overrides = + { + new Model.BranchConfiguration + { + Match = "^refs/heads/feature/.+$", + Label = new List { "{shortbranchname}" } + } + } + } + }; + Utils.WriteConfiguration(config, _repo); + + // Make some extra commits on master + _repo.MakeACommit(); + _repo.MakeACommit(); + _repo.MakeACommit(); + + // branch to a feature branch + _repo.BranchTo("feature/PBI-319594-GitVersionDeprecation"); + _repo.MakeACommit(); + _repo.MakeACommit(); + _repo.MakeACommit(); + + // Act + var result = GetResult(_repo); + + // Assert + result.Formats[Semver1FormatProcess.FormatKey].Should().Be("1.0.0-featurePBI319594GitVersionDeprecation-0007"); + result.Formats[Semver2FormatProcess.FormatKey].Should().Be("1.0.0-featurePBI319594GitVersionDeprecation.7"); + } + + private static Model.VersionResult GetResult(RepositoryFixtureBase repo) => VersionCalculator.Default().GetResult(repo.RepositoryPath); + } +}