forked from elastic/elasticsearch
/
ValidateChangelogEntryTaskTest.java
179 lines (141 loc) · 5.9 KB
/
ValidateChangelogEntryTaskTest.java
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.gradle.internal.release;
import org.gradle.api.GradleException;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
class ValidateChangelogEntryTaskTest {
@Test
void test_prNumber_isRequired() {
ChangelogEntry changelog = new ChangelogEntry();
changelog.setType("enhancement");
final String message = doValidate(changelog);
assertThat(message, endsWith("must provide a [pr] number (only 'known-issue' and 'security' entries can omit this"));
}
@Test
void test_prNumber_notRequired() {
Stream.of("known-issue", "security").forEach(type -> {
ChangelogEntry changelog = new ChangelogEntry();
changelog.setType(type);
// Should not throw an exception!
ValidateChangelogEntryTask.validate("", changelog);
});
}
@Test
void test_area_isRequired() {
final ChangelogEntry changelog = new ChangelogEntry();
changelog.setType("enhancement");
changelog.setPr(123);
final String message = doValidate(changelog);
assertThat(message, endsWith("must provide an [area] (only 'known-issue' and 'security' entries can omit this"));
}
@Test
void test_breaking_requiresBreakingSection() {
Stream.of("breaking", "breaking-java").forEach(type -> {
final ChangelogEntry changelog = buildChangelog(type);
final String message = doValidate(changelog);
assertThat(message, endsWith("has type [" + type + "] and must supply a [breaking] section with further information"));
});
}
@Test
void test_breaking_rejectsTripleBackticksInDetails() {
Stream.of("breaking", "breaking-java").forEach(type -> {
final ChangelogEntry.Breaking breaking = new ChangelogEntry.Breaking();
breaking.setDetails("""
Some waffle.
```
I AM CODE!
```
""");
final ChangelogEntry changelog = buildChangelog(type);
changelog.setBreaking(breaking);
final String message = doValidate(changelog);
assertThat(message, containsString("uses a triple-backtick in the [breaking.details] section"));
});
}
@Test
void test_breaking_rejectsTripleBackticksInImpact() {
Stream.of("breaking", "breaking-java").forEach(type -> {
final ChangelogEntry.Breaking breaking = new ChangelogEntry.Breaking();
breaking.setDetails("Waffle waffle");
breaking.setImpact("""
More waffle.
```
THERE ARE WEASEL RAKING THROUGH MY GARBAGE!
```
""");
final ChangelogEntry changelog = buildChangelog(type);
changelog.setBreaking(breaking);
final String message = doValidate(changelog);
assertThat(message, containsString("uses a triple-backtick in the [breaking.impact] section"));
});
}
@Test
void test_deprecation_rejectsTripleBackticksInImpact() {
final ChangelogEntry.Deprecation deprecation = new ChangelogEntry.Deprecation();
deprecation.setDetails("Waffle waffle");
deprecation.setImpact("""
More waffle.
```
THERE ARE WEASEL RAKING THROUGH MY GARBAGE!
```
""");
final ChangelogEntry changelog = buildChangelog("deprecation");
changelog.setDeprecation(deprecation);
final String message = doValidate(changelog);
assertThat(message, containsString("uses a triple-backtick in the [deprecation.impact] section"));
}
@Test
void test_deprecation_rejectsTripleBackticksInDetails() {
final ChangelogEntry.Deprecation deprecation = new ChangelogEntry.Deprecation();
deprecation.setDetails("""
Some waffle.
```
I AM CODE!
```
""");
final ChangelogEntry changelog = buildChangelog("deprecation");
changelog.setDeprecation(deprecation);
final String message = doValidate(changelog);
assertThat(message, containsString("uses a triple-backtick in the [deprecation.details] section"));
}
@Test
void test_highlight_rejectsTripleBackticksInBody() {
final ChangelogEntry.Highlight highlight = new ChangelogEntry.Highlight();
highlight.setBody("""
Some waffle.
```
I AM CODE!
```
""");
final ChangelogEntry changelog = buildChangelog("enhancement");
changelog.setHighlight(highlight);
final String message = doValidate(changelog);
assertThat(message, containsString("uses a triple-backtick in the [highlight.body] section"));
}
private static ChangelogEntry buildChangelog(String type) {
final ChangelogEntry changelog = new ChangelogEntry();
changelog.setType(type);
changelog.setPr(123);
changelog.setArea("Infra/Core");
return changelog;
}
private String doValidate(ChangelogEntry entry) {
try {
ValidateChangelogEntryTask.validate("docs/123.yaml", entry);
throw new AssertionError("No exception thrown!");
} catch (Exception e) {
assertThat(e, Matchers.instanceOf(GradleException.class));
return e.getMessage();
}
}
}