Skip to content

Commit 539f057

Browse files
committed
Revert to filtering _cat and _xpack/ml/datafeed APIs
1 parent b629d7e commit 539f057

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.gradle.api.tasks.OutputDirectory
2727

2828
import java.nio.file.Files
2929
import 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
}

buildSrc/src/test/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTaskTest.groovy

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package org.elasticsearch.gradle.doc
2121

22-
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.isDocWriteRequest
22+
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.shouldAddShardFailureCheck
2323
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.replaceBlockQuote
2424

2525
class RestTestFromSnippetsTaskTest extends GroovyTestCase {
@@ -47,9 +47,8 @@ class RestTestFromSnippetsTaskTest extends GroovyTestCase {
4747
}
4848

4949
void testIsDocWriteRequest() {
50-
assertTrue(isDocWriteRequest("doc-index/doc_id"));
51-
assertTrue(isDocWriteRequest("doc_index/doc_type/doc_id"));
52-
assertFalse(isDocWriteRequest("doc_index/_search"))
53-
assertFalse(isDocWriteRequest("_xpack/ml/datafeeds/datafeed-id/_preview"));
50+
assertTrue(shouldAddShardFailureCheck("doc-index/_search"));
51+
assertFalse(shouldAddShardFailureCheck("_cat"))
52+
assertFalse(shouldAddShardFailureCheck("_xpack/ml/datafeeds/datafeed-id/_preview"));
5453
}
5554
}

0 commit comments

Comments
 (0)