-
Notifications
You must be signed in to change notification settings - Fork 659
Expand file tree
/
Copy pathIgnoreConfigurationTests.cs
More file actions
164 lines (130 loc) · 4.88 KB
/
Copy pathIgnoreConfigurationTests.cs
File metadata and controls
164 lines (130 loc) · 4.88 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System.Globalization;
using GitVersion.Tests;
using GitVersion.VersionCalculation;
using SharpYaml;
namespace GitVersion.Configuration.Tests;
[TestFixture]
public class IgnoreConfigurationTests : TestBase
{
private readonly ConfigurationSerializer serializer = new();
[Test]
public void CanDeserialize()
{
const string yaml =
"""
ignore:
commits-before: 2015-10-23T12:23:15
sha: [b6c0c9fda88830ebcd563e500a5a7da5a1658e98]
""";
var configuration = this.serializer.ReadConfiguration(yaml);
configuration.ShouldNotBeNull();
configuration.Ignore.ShouldNotBeNull();
configuration.Ignore.Before.ShouldBe(DateTimeOffset.Parse("2015-10-23T12:23:15", CultureInfo.InvariantCulture));
configuration.Ignore.Shas.ShouldNotBeEmpty();
configuration.Ignore.Shas.ShouldBe(["b6c0c9fda88830ebcd563e500a5a7da5a1658e98"]);
}
[Test]
public void ShouldSupportsOtherSequenceFormat()
{
const string yaml =
"""
ignore:
sha:
- b6c0c9fda88830ebcd563e500a5a7da5a1658e98
- 6c19c7c219ecf8dbc468042baefa73a1b213e8b1
""";
var configuration = this.serializer.ReadConfiguration(yaml);
configuration.ShouldNotBeNull();
configuration.Ignore.ShouldNotBeNull();
configuration.Ignore.Shas.ShouldNotBeEmpty();
configuration.Ignore.Shas.ShouldBe(["b6c0c9fda88830ebcd563e500a5a7da5a1658e98", "6c19c7c219ecf8dbc468042baefa73a1b213e8b1"]);
}
[Test]
public void CanDeserializeCompactTagsSequence()
{
const string yaml = "ignore:\n tags: ['^preview-', '^v0\\.']";
var configuration = this.serializer.ReadConfiguration(yaml);
configuration.ShouldNotBeNull();
configuration.Ignore.Tags.ShouldBe(["^preview-", "^v0\\."]);
}
[Test]
public void CanDeserializeMultilineTagsSequence()
{
const string yaml =
"""
ignore:
tags:
- ^preview-
- ^v0\.
""";
var configuration = this.serializer.ReadConfiguration(yaml);
configuration.ShouldNotBeNull();
configuration.Ignore.Tags.ShouldBe(["^preview-", "^v0\\."]);
}
[Test]
public void WhenNotInConfigShouldHaveDefaults()
{
const string yaml = "next-version: 1.0";
var configuration = this.serializer.ReadConfiguration(yaml);
configuration.ShouldNotBeNull();
configuration.Ignore.ShouldNotBeNull();
configuration.Ignore.Before.ShouldBe(null);
configuration.Ignore.Paths.ShouldBeEmpty();
configuration.Ignore.Shas.ShouldBeEmpty();
configuration.Ignore.Tags.ShouldBeEmpty();
}
[Test]
public void IsEmpty_WhenTagPatternIsConfigured_ReturnsFalse()
{
var ignoreConfig = new IgnoreConfiguration { Tags = ["^preview-"] };
ignoreConfig.IsEmpty.ShouldBeFalse();
}
[Test]
public void InvalidIgnoreTagExpression_ThrowsConfigurationExceptionWithPropertyAndPattern()
{
const string invalidExpression = "[invalid";
var exception = Should.Throw<ConfigurationException>(() => GitFlowConfigurationBuilder.New
.WithIgnoreConfiguration(new IgnoreConfiguration { Tags = [invalidExpression] })
.Build());
exception.Message.ShouldContain("ignore.tags");
exception.Message.ShouldContain(invalidExpression);
}
[Test]
public void Serialize_IgnoreTagPatterns_UsesTagsPropertyName()
{
var ignoreConfig = new IgnoreConfiguration { Tags = ["^preview-"] };
var yaml = this.serializer.Serialize(ignoreConfig);
yaml.ShouldContain("tags:");
yaml.ShouldContain("^preview-");
}
[Test]
public void IgnoreConfigurationBuilder_WithTags_PreservesCollection()
{
var ignoreConfig = IgnoreConfigurationBuilder.New.WithTags("^preview-", "^v0\\.").Build();
ignoreConfig.Tags.ShouldBe(["^preview-", "^v0\\."]);
}
[Test]
public void WhenBadDateFormatShouldFail()
{
const string yaml =
"""
ignore:
commits-before: bad format date
""";
Should.Throw<YamlException>(() => this.serializer.ReadConfiguration(yaml));
}
[Test]
public void ShouldSupportScalarVersionStrategiesOverrideFormat()
{
const string yaml = "strategies: ConfiguredNextVersion, TaggedCommit";
var configuration = this.serializer.ReadConfiguration(yaml);
configuration.ShouldNotBeNull();
configuration.VersionStrategy.ShouldBe(VersionStrategies.ConfiguredNextVersion | VersionStrategies.TaggedCommit);
}
[Test]
public void NewInstanceShouldBeEmpty()
{
var ignoreConfig = new IgnoreConfiguration();
ignoreConfig.IsEmpty.ShouldBeTrue();
}
}