|
| 1 | +using GitVersion.Configuration; |
| 2 | +using GitVersion.Core.Tests; |
| 3 | +using GitVersion.Core.Tests.IntegrationTests; |
| 4 | +using GitVersion.VersionCalculation; |
| 5 | + |
| 6 | +namespace GitVersion.Core.TrunkBased; |
| 7 | + |
| 8 | +internal partial class TrunkBasedScenariosWithAGitFlow |
| 9 | +{ |
| 10 | + [Parallelizable(ParallelScope.All)] |
| 11 | + public class GivenADevelopBranchWithOneCommitMergedToMainWhenMergedCommitTaggedAsStable |
| 12 | + { |
| 13 | + private EmptyRepositoryFixture? fixture; |
| 14 | + |
| 15 | + private static GitFlowConfigurationBuilder TrunkBasedBuilder => GitFlowConfigurationBuilder.New.WithLabel(null) |
| 16 | + .WithVersionStrategy(VersionStrategies.TrunkBased) |
| 17 | + .WithBranch("main", _ => _.WithDeploymentMode(DeploymentMode.ManualDeployment)) |
| 18 | + .WithBranch("develop", _ => _.WithDeploymentMode(DeploymentMode.ManualDeployment)); |
| 19 | + |
| 20 | + [OneTimeSetUp] |
| 21 | + public void OneTimeSetUp() |
| 22 | + { |
| 23 | + // * 55 minutes ago (tag: 1.0.0, main) |
| 24 | + // |\ |
| 25 | + // | * 56 minutes ago (HEAD -> develop) |
| 26 | + // |/ |
| 27 | + // * 58 minutes ago |
| 28 | + |
| 29 | + fixture = new EmptyRepositoryFixture("main"); |
| 30 | + |
| 31 | + fixture.MakeACommit("A"); |
| 32 | + fixture.BranchTo("develop"); |
| 33 | + fixture.MakeACommit("B"); |
| 34 | + fixture.MergeTo("main"); |
| 35 | + fixture.ApplyTag("1.0.0"); |
| 36 | + fixture.Checkout("develop"); |
| 37 | + } |
| 38 | + |
| 39 | + [OneTimeTearDown] |
| 40 | + public void OneTimeTearDown() => fixture?.Dispose(); |
| 41 | + |
| 42 | + [TestCase(IncrementStrategy.None, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")] |
| 43 | + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")] |
| 44 | + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")] |
| 45 | + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")] |
| 46 | + |
| 47 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")] |
| 48 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")] |
| 49 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")] |
| 50 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")] |
| 51 | + |
| 52 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")] |
| 53 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")] |
| 54 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")] |
| 55 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")] |
| 56 | + |
| 57 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, ExpectedResult = "1.0.0-alpha.1+0")] |
| 58 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, ExpectedResult = "1.0.1-alpha.1+0")] |
| 59 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, ExpectedResult = "1.1.0-alpha.1+0")] |
| 60 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")] |
| 61 | + public string GetVersionWithTrackMergeTargetOnDevelop(IncrementStrategy incrementOnMain, IncrementStrategy increment) |
| 62 | + { |
| 63 | + IGitVersionConfiguration trunkBased = TrunkBasedBuilder |
| 64 | + .WithBranch("main", _ => _.WithIncrement(incrementOnMain).WithLabel(null)) |
| 65 | + .WithBranch("develop", _ => _.WithIncrement(increment).WithTrackMergeTarget(true)) |
| 66 | + .Build(); |
| 67 | + |
| 68 | + return fixture!.GetVersion(trunkBased).FullSemVer; |
| 69 | + } |
| 70 | + |
| 71 | + [TestCase(IncrementStrategy.None, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")] |
| 72 | + [TestCase(IncrementStrategy.None, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")] |
| 73 | + [TestCase(IncrementStrategy.None, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")] |
| 74 | + [TestCase(IncrementStrategy.None, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")] |
| 75 | + |
| 76 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")] |
| 77 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")] |
| 78 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")] |
| 79 | + [TestCase(IncrementStrategy.Patch, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")] |
| 80 | + |
| 81 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")] |
| 82 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")] |
| 83 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")] |
| 84 | + [TestCase(IncrementStrategy.Minor, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")] |
| 85 | + |
| 86 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.None, ExpectedResult = "0.0.0-alpha.1+2")] |
| 87 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.Patch, ExpectedResult = "0.0.1-alpha.1+2")] |
| 88 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.Minor, ExpectedResult = "0.1.0-alpha.1+2")] |
| 89 | + [TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "1.0.0-alpha.1+2")] |
| 90 | + public string GetVersionWithNoTrackMergeTargetOnDevelop(IncrementStrategy incrementOnMain, IncrementStrategy increment) |
| 91 | + { |
| 92 | + IGitVersionConfiguration trunkBased = TrunkBasedBuilder |
| 93 | + .WithBranch("main", _ => _.WithIncrement(incrementOnMain).WithLabel(null)) |
| 94 | + .WithBranch("develop", _ => _.WithIncrement(increment).WithTrackMergeTarget(false)) |
| 95 | + .Build(); |
| 96 | + |
| 97 | + return fixture!.GetVersion(trunkBased).FullSemVer; |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments