Skip to content

Commit baa144e

Browse files
authored
Enforce a [skip] when using [contains] (elastic#34840)
Be friendly to other runners
1 parent b2daaf1 commit baa144e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public void addExecutableSection(ExecutableSection executableSection) {
9999
+ doSection.getLocation().lineNumber + "]");
100100
}
101101
}
102+
if (executableSection instanceof ContainsAssertion) {
103+
if (false == skipSection.getFeatures().contains("contains")) {
104+
throw new IllegalArgumentException("Attempted to add a [contains] assertion without a corresponding "
105+
+ "[skip: \"features\": \"contains\"] so runners that do not support the [contains] assertion " +
106+
"can skip the test at line [" + executableSection.getLocation().lineNumber + "]");
107+
}
108+
}
102109
this.executableSections.add(executableSection);
103110
}
104111

test/framework/src/test/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSectionTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,27 @@ public void testSmallSection() throws Exception {
328328
assertThat(testSection.getExecutableSections().size(), equalTo(3));
329329
}
330330

331+
public void testAddingContainsWithoutSkip() {
332+
int lineNumber = between(1, 10000);
333+
ClientYamlTestSection section = new ClientYamlTestSection(new XContentLocation(0, 0), "test");
334+
if (randomBoolean()) {
335+
section.setSkipSection(new SkipSection(null, singletonList("yaml"), null));
336+
} else {
337+
section.setSkipSection(SkipSection.EMPTY);
338+
}
339+
Exception e = expectThrows(
340+
IllegalArgumentException.class,
341+
() -> section.addExecutableSection(
342+
new ContainsAssertion(
343+
new XContentLocation(lineNumber, 0),
344+
randomAlphaOfLength(randomIntBetween(3, 30)),
345+
randomDouble()
346+
)
347+
)
348+
);
349+
assertEquals("Attempted to add a [contains] assertion without a corresponding " +
350+
"[skip: \"features\": \"contains\"] so runners that do not support the [contains] assertion " +
351+
"can skip the test at line [" + lineNumber + "]", e.getMessage());
352+
}
353+
331354
}

0 commit comments

Comments
 (0)