Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Omit shard failures assertion for incompatible responses #31430

Merged
merged 3 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.gradle.api.tasks.OutputDirectory

import java.nio.file.Files
import java.nio.file.Path
import java.util.regex.Matcher
import java.util.regex.Pattern

/**
* Generates REST tests for each snippet marked // TEST.
Expand All @@ -39,6 +39,12 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
*/
private static final List BAD_LANGUAGES = ['json', 'javascript']

/**
* Doc write operations start with an index name that cannot
* start with -, _ or + and must be lower case.
*/
private static final Pattern DOCS_WRITE_OP_PATTERN = Pattern.compile("^[^_\\-\\+][a-z_-]+/");

@Input
Map<String, String> setups = new HashMap()

Expand Down Expand Up @@ -100,6 +106,13 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
return snippet.language == 'js' || snippet.curl
}

/**
* Is the URL path a doc write request?
*/
static isDocWriteRequest(String path) {
return DOCS_WRITE_OP_PATTERN.matcher(path).find();
}

/**
* Converts Kibana's block quoted strings into standard JSON. These
* {@code """} delimited strings can be embedded in CONSOLE and can
Expand Down Expand Up @@ -308,14 +321,12 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
/* Catch any shard failures. These only cause a non-200 response if
* no shard succeeds. But we need to fail the tests on all of these
* because they mean invalid syntax or broken queries or something
* else that we don't want to teach people to do. The REST test
* framework doesn't allow us to has assertions in the setup
* section so we have to skip it there. We also have to skip _cat
* actions because they don't return json so we can't is_false
* them. That is ok because they don't have this
* partial-success-is-success thing.
* else that we don't want to teach people to do. Shard failures
* can occur in document CRUD operations. The REST test
* framework doesn't allow us to have assertions in the setup
* section so we have to skip it there.
*/
if (false == inSetup && false == path.startsWith('_cat')) {
if (false == inSetup && isDocWriteRequest(path)) {
current.println(" - is_false: _shards.failures")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

package org.elasticsearch.gradle.doc

import org.elasticsearch.gradle.doc.SnippetsTask.Snippet
import org.gradle.api.InvalidUserDataException

import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.isDocWriteRequest
import static org.elasticsearch.gradle.doc.RestTestsFromSnippetsTask.replaceBlockQuote

class RestTestFromSnippetsTaskTest extends GroovyTestCase {
Expand All @@ -47,4 +45,11 @@ class RestTestFromSnippetsTaskTest extends GroovyTestCase {
assertEquals("\"foo\": \"bort\\n baz\"",
replaceBlockQuote("\"foo\": \"\"\"bort\n baz\"\"\""));
}

void testIsDocWriteRequest() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the name of the test?

assertTrue(isDocWriteRequest("doc-index/doc_id"));
assertTrue(isDocWriteRequest("doc_index/doc_type/doc_id"));
assertFalse(isDocWriteRequest("doc_index"))
assertFalse(isDocWriteRequest("_xpack/ml/datafeeds/datafeed-id/_preview"));
}
}