Skip to content

Commit e75c51e

Browse files
committed
Test: better error message on failure
The `DefaultShardIT` test wasn't giving as much information I'd like on failure so I added a bit more.
1 parent 2dd7e3f commit e75c51e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/DefaultShardsIT.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.test.rest;
2121

22+
import org.apache.http.util.EntityUtils;
2223
import org.elasticsearch.client.Request;
2324
import org.elasticsearch.client.Response;
2425

@@ -34,8 +35,16 @@ public class DefaultShardsIT extends ESRestTestCase {
3435
public void testDefaultShards() throws IOException {
3536
final Response response = client().performRequest(new Request("PUT", "/index"));
3637
final String warning = response.getHeader("Warning");
38+
if (warning == null) {
39+
StringBuilder explanation = new StringBuilder("expected response to contain a warning but did not ");
40+
explanation.append(response);
41+
if (response.getEntity() != null) {
42+
explanation.append(" entity:\n").append(EntityUtils.toString(response.getEntity()));
43+
}
44+
fail(explanation.toString());
45+
}
3746
final Matcher matcher = WARNING_HEADER_PATTERN.matcher(warning);
38-
assertTrue(matcher.matches());
47+
assertTrue("warning didn't match warning header pattern but was [" + warning + "]", matcher.matches());
3948
final String message = matcher.group(1);
4049
assertThat(message, equalTo("the default number of shards will change from [5] to [1] in 7.0.0; "
4150
+ "if you wish to continue using the default of [5] shards, "

0 commit comments

Comments
 (0)