Skip to content

Commit 60b4be6

Browse files
committed
[DOCS] Omit shard failures assertion for incompatible responses (#31430)
Filter out the assertion for _cat and _xpack/ml/datafeed APIs
1 parent 1a1164c commit 60b4be6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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

Lines changed: 12 additions & 7 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.Matcher
3130

3231
/**
3332
* Generates REST tests for each snippet marked // TEST.
@@ -100,6 +99,14 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
10099
return snippet.language == 'js' || snippet.curl
101100
}
102101

102+
/**
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.
105+
*/
106+
static shouldAddShardFailureCheck(String path) {
107+
return path.startsWith('_cat') == false && path.startsWith('_xpack/ml/datafeeds/') == false
108+
}
109+
103110
/**
104111
* Converts Kibana's block quoted strings into standard JSON. These
105112
* {@code """} delimited strings can be embedded in CONSOLE and can
@@ -308,13 +315,11 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
308315
* no shard succeeds. But we need to fail the tests on all of these
309316
* because they mean invalid syntax or broken queries or something
310317
* else that we don't want to teach people to do. The REST test
311-
* framework doesn't allow us to has assertions in the setup
312-
* section so we have to skip it there. We also have to skip _cat
313-
* actions because they don't return json so we can't is_false
314-
* them. That is ok because they don't have this
315-
* partial-success-is-success thing.
318+
* framework doesn't allow us to have assertions in the setup
319+
* section so we have to skip it there. We also omit the assertion
320+
* from APIs that don't return a JSON object
316321
*/
317-
if (false == inSetup && false == path.startsWith('_cat')) {
322+
if (false == inSetup && shouldAddShardFailureCheck(path)) {
318323
current.println(" - is_false: _shards.failures")
319324
}
320325
}

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

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

2020
package org.elasticsearch.gradle.doc
2121

22-
import org.elasticsearch.gradle.doc.SnippetsTask.Snippet
23-
import org.gradle.api.InvalidUserDataException
24-
22+
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.shouldAddShardFailureCheck
2523
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.replaceBlockQuote
2624

2725
class RestTestFromSnippetsTaskTest extends GroovyTestCase {
@@ -47,4 +45,10 @@ class RestTestFromSnippetsTaskTest extends GroovyTestCase {
4745
assertEquals("\"foo\": \"bort\\n baz\"",
4846
replaceBlockQuote("\"foo\": \"\"\"bort\n baz\"\"\""));
4947
}
48+
49+
void testIsDocWriteRequest() {
50+
assertTrue(shouldAddShardFailureCheck("doc-index/_search"));
51+
assertFalse(shouldAddShardFailureCheck("_cat"))
52+
assertFalse(shouldAddShardFailureCheck("_xpack/ml/datafeeds/datafeed-id/_preview"));
53+
}
5054
}

0 commit comments

Comments
 (0)