@@ -27,7 +27,6 @@ import org.gradle.api.tasks.OutputDirectory
2727
2828import java.nio.file.Files
2929import java.nio.file.Path
30- import java.util.regex.Pattern
3130
3231/**
3332 * Generates REST tests for each snippet marked // TEST.
@@ -39,14 +38,6 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
3938 */
4039 private static final List BAD_LANGUAGES = [' json' , ' javascript' ]
4140
42- /**
43- * Doc write operations start with an index name that cannot
44- * start with -, _ or + and must be lower case and are followed
45- * by the doc type or doc Id. If the 2nd part of the path
46- * (after the '/') starts with a '_' then it is an API call.
47- */
48- private static final Pattern DOCS_WRITE_OP_PATTERN = Pattern . compile(" ^[^_\\ -\\ +][a-z_-]+/[^_]" );
49-
5041 @Input
5142 Map<String , String > setups = new HashMap ()
5243
@@ -109,10 +100,11 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
109100 }
110101
111102 /**
112- * Is the URL path a doc write request?
103+ * Certain requests should not have the shard failure check because the
104+ * format of the response is incompatible i.e. it is not a JSON object.
113105 */
114- static isDocWriteRequest (String path ) {
115- return DOCS_WRITE_OP_PATTERN . matcher(path) . find();
106+ static shouldAddShardFailureCheck (String path ) {
107+ return path . startsWith( ' _cat ' ) == false && path . startsWith( ' _xpack/ml/datafeeds/ ' ) == false
116108 }
117109
118110 /**
@@ -323,12 +315,12 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
323315 /* Catch any shard failures. These only cause a non-200 response if
324316 * no shard succeeds. But we need to fail the tests on all of these
325317 * because they mean invalid syntax or broken queries or something
326- * else that we don't want to teach people to do. Shard failures
327- * can occur in document CRUD operations. The REST test
318+ * else that we don't want to teach people to do. The REST test
328319 * framework doesn't allow us to have assertions in the setup
329- * section so we have to skip it there.
320+ * section so we have to skip it there. We also omit the assertion
321+ * from APIs that don't return a JSON object
330322 */
331- if (false == inSetup && isDocWriteRequest (path)) {
323+ if (false == inSetup && shouldAddShardFailureCheck (path)) {
332324 current. println (" - is_false: _shards.failures" )
333325 }
334326 }
0 commit comments