Skip to content

Commit 7a9b035

Browse files
brianseedersmridula-s109
authored andcommitted
[release-notes] Fix tests and make it easy to regenerate output after changes (elastic#128781)
1 parent b61ffc4 commit 7a9b035

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/release/ReleaseNotesGeneratorTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020

2121
import static org.elasticsearch.gradle.internal.release.GenerateReleaseNotesTask.getSortedBundlesWithUniqueChangelogs;
2222
import static org.hamcrest.Matchers.equalTo;
23+
import static org.junit.Assert.assertFalse;
2324
import static org.junit.Assert.assertThat;
2425

2526
public class ReleaseNotesGeneratorTest {
2627

28+
// Temporarily set this to `true` to regenerate test output files when they need to be updated
29+
private final boolean UPDATE_EXPECTED_OUTPUT = false;
30+
2731
private static final List<String> CHANGE_TYPES = List.of(
2832
"breaking",
2933
"breaking-java",
@@ -78,8 +82,9 @@ public void testTemplate(String templateFilename, String outputFilename) throws
7882

7983
public void testTemplate(String templateFilename, String outputFilename, List<ChangelogBundle> bundles) throws Exception {
8084
// given:
85+
final String outputFile = "/org/elasticsearch/gradle/internal/release/ReleaseNotesGeneratorTest." + outputFilename;
8186
final String template = getResource("/templates/" + templateFilename);
82-
final String expectedOutput = getResource("/org/elasticsearch/gradle/internal/release/ReleaseNotesGeneratorTest." + outputFilename);
87+
final String expectedOutput = getResource(outputFile);
8388

8489
if (bundles == null) {
8590
bundles = getBundles();
@@ -91,7 +96,12 @@ public void testTemplate(String templateFilename, String outputFilename, List<Ch
9196
final String actualOutput = ReleaseNotesGenerator.generateFile(template, bundles);
9297

9398
// then:
94-
assertThat(actualOutput, equalTo(expectedOutput));
99+
if (UPDATE_EXPECTED_OUTPUT) {
100+
writeResource(outputFile, actualOutput);
101+
assertFalse("UPDATE_EXPECTED_OUTPUT should be set back to false after updating output", UPDATE_EXPECTED_OUTPUT);
102+
} else {
103+
assertThat(actualOutput, equalTo(expectedOutput));
104+
}
95105
}
96106

97107
private List<ChangelogBundle> getBundles() {
@@ -176,4 +186,9 @@ private ChangelogEntry makeHighlightsEntry(int pr, boolean notable) {
176186
private String getResource(String name) throws Exception {
177187
return Files.readString(Paths.get(Objects.requireNonNull(this.getClass().getResource(name)).toURI()), StandardCharsets.UTF_8);
178188
}
189+
190+
private void writeResource(String name, String contents) throws Exception {
191+
String path = "src/test/resources" + name;
192+
Files.writeString(Paths.get(path), contents);
193+
}
179194
}

build-tools-internal/src/test/resources/org/elasticsearch/gradle/internal/release/ReleaseNotesGeneratorTest.index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ To check for security updates, go to [Security announcements for the Elastic sta
2020
% ### Fixes [elasticsearch-next-fixes]
2121
% *
2222

23+
## 9.1.0 [elasticsearch-9.1.0-release-notes]
2324
```{applies_to}
2425
stack: coming 9.1.0
2526
```
26-
## 9.1.0 [elasticsearch-9.1.0-release-notes]
2727

2828
### Highlights [elasticsearch-9.1.0-highlights]
2929

@@ -47,10 +47,10 @@ Search:
4747
* [#52](https://github.com/elastic/elasticsearch/pull/52)
4848

4949

50+
## 9.0.10 [elasticsearch-9.0.10-release-notes]
5051
```{applies_to}
5152
stack: coming 9.0.10
5253
```
53-
## 9.0.10 [elasticsearch-9.0.10-release-notes]
5454

5555
### Features and enhancements [elasticsearch-9.0.10-features-enhancements]
5656

build-tools-internal/src/test/resources/org/elasticsearch/gradle/internal/release/ReleaseNotesGeneratorTest.index.no-highlights.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ To check for security updates, go to [Security announcements for the Elastic sta
2020
% ### Fixes [elasticsearch-next-fixes]
2121
% *
2222

23+
## 9.0.10 [elasticsearch-9.0.10-release-notes]
2324
```{applies_to}
2425
stack: coming 9.0.10
2526
```
26-
## 9.0.10 [elasticsearch-9.0.10-release-notes]
2727

2828
### Features and enhancements [elasticsearch-9.0.10-features-enhancements]
2929

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,6 @@ tests:
534534
- class: org.elasticsearch.packaging.test.DockerTests
535535
method: test040JavaUsesTheOsProvidedKeystore
536536
issue: https://github.com/elastic/elasticsearch/issues/128230
537-
- class: org.elasticsearch.gradle.internal.release.ReleaseNotesGeneratorTest
538-
method: generateFile_index_rendersCorrectMarkup
539-
issue: https://github.com/elastic/elasticsearch/issues/128772
540-
- class: org.elasticsearch.gradle.internal.release.ReleaseNotesGeneratorTest
541-
method: generateFile_index_noHighlights_rendersCorrectMarkup
542-
issue: https://github.com/elastic/elasticsearch/issues/128773
543537
- class: org.elasticsearch.xpack.rank.rrf.LinearRankClientYamlTestSuiteIT
544538
method: test {yaml=linear/10_linear_retriever/should normalize initial scores with l2_norm}
545539
issue: https://github.com/elastic/elasticsearch/issues/128774

0 commit comments

Comments
 (0)