Skip to content

Commit 4f81d49

Browse files
authored
Change assertion so it works in every locale (elastic#138984)
1 parent aa837cb commit 4f81d49

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ tests:
463463
- class: org.elasticsearch.common.settings.ScopedSettingsTests
464464
method: testValidateArchivedSetting
465465
issue: https://github.com/elastic/elasticsearch/issues/138895
466-
- class: org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCaseMultipleFailuresIT
467-
method: test {p0=/20_multiple_failures/Test with multiple failures}
468-
issue: https://github.com/elastic/elasticsearch/issues/138896
469466
- class: org.elasticsearch.test.rest.yaml.CcsCommonYamlTestSuiteIT
470467
method: test {p0=search/610_function_score/formulating a function score query with a negative number returns bad request}
471468
issue: https://github.com/elastic/elasticsearch/issues/138908

test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public void verify() throws AssertionError {
587587
try {
588588
super.verify();
589589
} catch (Throwable e) {
590-
throw new AssertionError(e.getMessage());
590+
throw new AssertionError(e);
591591
}
592592
}
593593
}

test/yaml-rest-runner/src/yamlRestTest/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCaseMultipleFailuresIT.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1515
import org.elasticsearch.test.junit.annotations.TestLogging;
1616
import org.junit.ClassRule;
17+
import org.junit.runners.model.MultipleFailureException;
1718

1819
import java.io.IOException;
1920
import java.util.Collections;
2021

22+
import static org.hamcrest.Matchers.containsInAnyOrder;
2123
import static org.hamcrest.Matchers.containsString;
24+
import static org.hamcrest.Matchers.hasSize;
25+
import static org.hamcrest.Matchers.hasToString;
26+
import static org.hamcrest.Matchers.instanceOf;
2227

2328
public class ESClientYamlSuiteTestCaseMultipleFailuresIT extends ESClientYamlSuiteTestCase {
2429

@@ -48,14 +53,17 @@ public void test() throws IOException {
4853
try {
4954
super.test();
5055
} catch (AssertionError error) {
51-
String message = error.getMessage();
52-
assertThat("Error message should start with failure count", message, containsString("There were 3 errors"));
53-
assertThat("Error message should contain first failure", message, containsString("wrong_value1"));
54-
assertThat("Error message should contain second failure", message, containsString("wrong_value2"));
55-
assertThat("Error message should contain third failure", message, containsString("wrong_value3"));
56-
assertThat("Error message should contain actual value1", message, containsString("value1"));
57-
assertThat("Error message should contain actual value2", message, containsString("value2"));
58-
assertThat("Error message should contain actual value3", message, containsString("value3"));
56+
assertThat(error.getCause(), instanceOf(MultipleFailureException.class));
57+
MultipleFailureException cause = (MultipleFailureException) error.getCause();
58+
assertThat(cause.getFailures(), hasSize(3));
59+
assertThat(
60+
cause.getFailures(),
61+
containsInAnyOrder(
62+
hasToString(containsString("wrong_value1")),
63+
hasToString(containsString("wrong_value2")),
64+
hasToString(containsString("wrong_value3"))
65+
)
66+
);
5967
}
6068
}
6169

0 commit comments

Comments
 (0)