forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVersionInBranchNameBaseVersionStrategyTests.cs
More file actions
127 lines (96 loc) · 5.08 KB
/
VersionInBranchNameBaseVersionStrategyTests.cs
File metadata and controls
127 lines (96 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Extensions;
using GitVersion.Git;
using GitVersion.VersionCalculation;
namespace GitVersion.Core.Tests.VersionCalculation.Strategies;
[TestFixture]
public class VersionInBranchNameBaseVersionStrategyTests : TestBase
{
[TestCase("release-2.0.0", "2.0.0")]
[TestCase("release/3.0.0", "3.0.0")]
public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expectedBaseVersion)
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit();
fixture.CreateBranch(branchName);
var repository = fixture.Repository.ToGitRepository();
var strategy = GetVersionStrategy(repository);
var branch = repository.FindBranch(branchName);
var configuration = GitFlowConfigurationBuilder.New.Build();
var effectiveBranchConfiguration = configuration.GetEffectiveBranchConfiguration(branch);
strategy.ShouldNotBeNull();
var baseVersion = strategy.GetBaseVersions(effectiveBranchConfiguration).Single();
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
}
[TestCase("origin/hotfix-2.0.0")]
[TestCase("remotes/origin/hotfix-2.0.0")]
[TestCase("origin/hotfix/2.0.0")]
[TestCase("remotes/origin/hotfix/2.0.0")]
[TestCase("custom/JIRA-123")]
[TestCase("remotes/custom/JIRA-123")]
[TestCase("hotfix/downgrade-to-gitversion-3.6.5-to-fix-miscalculated-version")]
[TestCase("remotes/hotfix/downgrade-to-gitversion-3.6.5-to-fix-miscalculated-version")]
public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName)
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit();
fixture.CreateBranch(branchName);
var repository = fixture.Repository.ToGitRepository();
var strategy = GetVersionStrategy(repository);
var branch = repository.FindBranch(branchName);
var configuration = GitFlowConfigurationBuilder.New.Build();
var effectiveBranchConfiguration = configuration.GetEffectiveBranchConfiguration(branch);
strategy.ShouldNotBeNull();
var baseVersions = strategy.GetBaseVersions(effectiveBranchConfiguration);
baseVersions.ShouldBeEmpty();
}
[TestCase("release-2.0.0", "2.0.0")]
[TestCase("release/3.0.0", "3.0.0")]
[TestCase("support/2.0.0-lts", "2.0.0")]
[TestCase("support-3.0.0-lts", "3.0.0")]
[TestCase("hotfix/2.0.0", "2.0.0")]
[TestCase("hotfix-3.0.0", "3.0.0")]
[TestCase("hotfix/2.0.0-lts", "2.0.0")]
[TestCase("hotfix-3.0.0-lts", "3.0.0")]
public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, string expectedBaseVersion)
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit();
fixture.CreateBranch(branchName);
var repository = fixture.Repository.ToGitRepository();
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("support", builder => builder.WithIsReleaseBranch(true))
.Build();
ConfigurationHelper configurationHelper = new(configuration);
var strategy = GetVersionStrategy(repository, null, configurationHelper.Dictionary);
var branch = repository.FindBranch(branchName);
var effectiveBranchConfiguration = configuration.GetEffectiveBranchConfiguration(branch);
strategy.ShouldNotBeNull();
var baseVersion = strategy.GetBaseVersions(effectiveBranchConfiguration).Single();
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
}
[TestCase("origin", "release-2.0.0", "2.0.0")]
[TestCase("origin", "release/3.0.0", "3.0.0")]
public void CanTakeVersionFromNameOfRemoteReleaseBranch(string origin, string branchName, string expectedBaseVersion)
{
using var fixture = new RemoteRepositoryFixture();
fixture.CreateBranch(branchName);
if (origin != "origin") fixture.LocalRepositoryFixture.Repository.Network.Remotes.RenameRemote("origin", origin);
fixture.LocalRepositoryFixture.Fetch(origin);
var localRepository = fixture.LocalRepositoryFixture.Repository.ToGitRepository();
var strategy = GetVersionStrategy(localRepository);
var branch = localRepository.FindBranch(branchName);
var configuration = GitFlowConfigurationBuilder.New.Build();
var effectiveBranchConfiguration = configuration.GetEffectiveBranchConfiguration(branch);
strategy.ShouldNotBeNull();
var baseVersion = strategy.GetBaseVersions(effectiveBranchConfiguration).Single();
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
}
private static IVersionStrategy GetVersionStrategy(IGitRepository repository,
string? targetBranch = null, IReadOnlyDictionary<object, object?>? overrideConfiguration = null)
{
var serviceProvider = BuildServiceProvider(repository, targetBranch, overrideConfiguration);
return serviceProvider.GetServiceForType<IVersionStrategy, VersionInBranchNameVersionStrategy>();
}
}