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

[TEST] Enforce skip headers when needed #34735

Merged
merged 37 commits into from Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0779af3
[TEST] Enforce skip headers when needed
javanna Oct 23, 2018
5ac6010
adjusted tests
javanna Oct 23, 2018
e681ef5
remove constructor
javanna Oct 23, 2018
0ff7065
remove connection manager public constructor
javanna Oct 23, 2018
1c3232b
Merge branch 'master' into test/yaml_enforce_skip_headers
javanna Oct 24, 2018
eded609
Revert "remove connection manager public constructor"
javanna Oct 24, 2018
98f6a73
Revert "remove constructor"
javanna Oct 24, 2018
cef3ccc
Revert "adjusted tests"
javanna Oct 24, 2018
86fdf86
address comment
javanna Oct 24, 2018
79b0eb9
increase existings tests coverage
javanna Oct 24, 2018
fbb6c30
fix broken test
javanna Oct 24, 2018
b4181a2
fix test
javanna Oct 24, 2018
f94e70f
fix test
javanna Oct 24, 2018
291fd14
Merge branch 'master' into test/yaml_enforce_skip_headers
javanna Oct 24, 2018
f8ecf2e
adjusted tests
javanna Oct 25, 2018
85bad24
Merge branch 'master' into test/yaml_enforce_skip_headers
javanna Oct 25, 2018
7083d3e
fix test
javanna Oct 25, 2018
f02d425
improve validation of do sections
javanna Oct 25, 2018
3a94043
Revert "adjusted tests"
javanna Oct 25, 2018
096245d
Revert "fix test"
javanna Oct 25, 2018
2197850
fix bad merge
javanna Oct 25, 2018
3fe837d
Revert "fix test"
javanna Oct 25, 2018
9951f88
reverted change
javanna Oct 25, 2018
88bd211
remove empty line
javanna Oct 25, 2018
fdbc5e0
checkstyle
javanna Oct 25, 2018
a1f0614
Merge branch 'master' into test/yaml_enforce_skip_headers
javanna Oct 25, 2018
906e310
fix more tests and improve validation
javanna Oct 26, 2018
2a71b39
fix test
javanna Oct 26, 2018
7fd8472
fix test
javanna Oct 26, 2018
ef73010
fix ml tests
javanna Oct 26, 2018
46938ca
make setup, teardown and test sections immutable and improve validation
javanna Oct 26, 2018
853839e
fix tests
javanna Oct 27, 2018
959107f
fix more tests
javanna Oct 28, 2018
de2f816
Merge branch 'master' into test/yaml_enforce_skip_headers
javanna Oct 30, 2018
794a8c1
Merge branch 'master' into test/yaml_enforce_skip_headers
javanna Oct 30, 2018
e2a17f2
fix bad merge
javanna Oct 30, 2018
c75c0cc
improve test
javanna Oct 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -82,6 +82,9 @@

---
"Find a task result record from the old cluster":
- skip:
features: headers

- do:
search:
index: .tasks
Expand Down
Expand Up @@ -86,7 +86,6 @@ public static ClientYamlTestSuite parse(String api, String suiteName, XContentPa

SetupSection setupSection = SetupSection.parseIfNext(parser);
TeardownSection teardownSection = TeardownSection.parseIfNext(parser);

Set<ClientYamlTestSection> testSections = new TreeSet<>();
while(true) {
//the "---" section separator is not understood by the yaml parser. null is returned, same as when the parser is closed
Expand Down Expand Up @@ -179,6 +178,14 @@ private static Stream<String> validateExecutableSections(List<ExecutableSection>
"without a corresponding [\"skip\": \"features\": \"contains\"] so runners that do not support the " +
"[contains] assertion can skip the test at line [" + section.getLocation().lineNumber + "]"));

errors = Stream.concat(errors, sections.stream().filter(section -> section instanceof DoSection)
.map(section -> (DoSection) section)
.filter(section -> false == section.getApiCallSection().getHeaders().isEmpty())
.filter(section -> false == hasSkipFeature("headers", testSection, setupSection, teardownSection))
.map(section -> "attempted to add a [do] with a [headers] section without a corresponding "
+ "[\"skip\": \"features\": \"headers\"] so runners that do not support the [headers] section can skip the test at " +
"line [" + section.getLocation().lineNumber + "]"));

return errors;
}

Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
Expand Down Expand Up @@ -403,11 +404,24 @@ public void testAddingDoWithWarningWithoutSkipWarnings() {
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
doSection.setExpectedWarningHeaders(singletonList("foo"));
doSection.setApiCallSection(new ApiCallSection("test"));
ClientYamlTestSuite testSuite = createTestSuite(doSection);
ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection);
Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
assertEquals("api/name:\nattempted to add a [do] with a [warnings] section without a corresponding " +
assertThat(e.getMessage(), containsString("api/name:\nattempted to add a [do] with a [warnings] section without a corresponding " +
"[\"skip\": \"features\": \"warnings\"] so runners that do not support the [warnings] section can skip the test " +
"at line [" + lineNumber + "]", e.getMessage());
"at line [" + lineNumber + "]"));
}

public void testAddingDoWithHeaderWithoutSkipHeaders() {
int lineNumber = between(1, 10000);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
ApiCallSection apiCallSection = new ApiCallSection("test");
apiCallSection.addHeaders(Collections.singletonMap("header", "value"));
doSection.setApiCallSection(apiCallSection);
ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection);
Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
assertThat(e.getMessage(), containsString("api/name:\nattempted to add a [do] with a [headers] section without a corresponding " +
"[\"skip\": \"features\": \"headers\"] so runners that do not support the [headers] section can skip the test at line ["
+ lineNumber + "]"));
}

public void testAddingDoWithNodeSelectorWithoutSkipNodeSelector() {
Expand All @@ -416,11 +430,11 @@ public void testAddingDoWithNodeSelectorWithoutSkipNodeSelector() {
ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS);
doSection.setApiCallSection(apiCall);
ClientYamlTestSuite testSuite = createTestSuite(doSection);
ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection);
Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
assertEquals("api/name:\nattempted to add a [do] with a [node_selector] section without a corresponding"
+ " [\"skip\": \"features\": \"node_selector\"] so runners that do not support the [node_selector] section can skip the test at"
+ " line [" + lineNumber + "]", e.getMessage());
assertThat(e.getMessage(), containsString("api/name:\nattempted to add a [do] with a [node_selector] section without a " +
"corresponding [\"skip\": \"features\": \"node_selector\"] so runners that do not support the [node_selector] section can " +
"skip the test at line [" + lineNumber + "]"));
}

public void testAddingContainsWithoutSkipContains() {
Expand All @@ -429,11 +443,11 @@ public void testAddingContainsWithoutSkipContains() {
new XContentLocation(lineNumber, 0),
randomAlphaOfLength(randomIntBetween(3, 30)),
randomDouble());
ClientYamlTestSuite testSuite = createTestSuite(containsAssertion);
ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, containsAssertion);
Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
assertEquals("api/name:\nattempted to add a [contains] assertion without a corresponding " +
assertThat(e.getMessage(), containsString("api/name:\nattempted to add a [contains] assertion without a corresponding " +
"[\"skip\": \"features\": \"contains\"] so runners that do not support the [contains] assertion " +
"can skip the test at line [" + lineNumber + "]", e.getMessage());
"can skip the test at line [" + lineNumber + "]"));
}

public void testMultipleValidationErrors() {
Expand Down Expand Up @@ -477,44 +491,13 @@ public void testMultipleValidationErrors() {
e.getMessage());
}

private static ClientYamlTestSuite createTestSuite(ExecutableSection executableSection) {
final SetupSection setupSection;
final TeardownSection teardownSection;
final ClientYamlTestSection clientYamlTestSection;
switch(randomIntBetween(0, 2)) {
case 0:
setupSection = new SetupSection(SkipSection.EMPTY, Collections.singletonList(executableSection));
teardownSection = TeardownSection.EMPTY;
clientYamlTestSection = new ClientYamlTestSection(new XContentLocation(0, 0), "test",
SkipSection.EMPTY, Collections.emptyList());
break;
case 1:
setupSection = SetupSection.EMPTY;
teardownSection = new TeardownSection(SkipSection.EMPTY, Collections.singletonList(executableSection));
clientYamlTestSection = new ClientYamlTestSection(new XContentLocation(0, 0), "test",
SkipSection.EMPTY, Collections.emptyList());
break;
case 2:
setupSection = SetupSection.EMPTY;
teardownSection = TeardownSection.EMPTY;
clientYamlTestSection = new ClientYamlTestSection(new XContentLocation(0, 0), "test",
SkipSection.EMPTY, Collections.singletonList(executableSection));
break;
default:
throw new UnsupportedOperationException();
}

return new ClientYamlTestSuite("api", "name", setupSection, teardownSection,
Collections.singletonList(clientYamlTestSection));
}

public void testAddingDoWithWarningWithSkip() {
int lineNumber = between(1, 10000);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
doSection.setExpectedWarningHeaders(singletonList("foo"));
doSection.setApiCallSection(new ApiCallSection("test"));
SkipSection skipSection = new SkipSection(null, singletonList("warnings"), null);
createTestSuiteAndValidate(skipSection, doSection);
createTestSuite(skipSection, doSection).validate();
}

public void testAddingDoWithNodeSelectorWithSkip() {
Expand All @@ -524,7 +507,17 @@ public void testAddingDoWithNodeSelectorWithSkip() {
ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS);
doSection.setApiCallSection(apiCall);
createTestSuiteAndValidate(skipSection, doSection);
createTestSuite(skipSection, doSection).validate();
}

public void testAddingDoWithHeadersWithSkip() {
int lineNumber = between(1, 10000);
SkipSection skipSection = new SkipSection(null, singletonList("headers"), null);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
ApiCallSection apiCallSection = new ApiCallSection("test");
apiCallSection.addHeaders(singletonMap("foo", "bar"));
doSection.setApiCallSection(apiCallSection);
createTestSuite(skipSection, doSection).validate();
}

public void testAddingContainsWithSkip() {
Expand All @@ -534,10 +527,10 @@ public void testAddingContainsWithSkip() {
new XContentLocation(lineNumber, 0),
randomAlphaOfLength(randomIntBetween(3, 30)),
randomDouble());
createTestSuiteAndValidate(skipSection, containsAssertion);
createTestSuite(skipSection, containsAssertion).validate();
}

private static void createTestSuiteAndValidate(SkipSection skipSection, ExecutableSection executableSection) {
private static ClientYamlTestSuite createTestSuite(SkipSection skipSection, ExecutableSection executableSection) {
final SetupSection setupSection;
final TeardownSection teardownSection;
final ClientYamlTestSection clientYamlTestSection;
Expand Down Expand Up @@ -571,13 +564,11 @@ private static void createTestSuiteAndValidate(SkipSection skipSection, Executab
teardownSection = new TeardownSection(skipSection, Collections.singletonList(executableSection));
clientYamlTestSection = new ClientYamlTestSection(new XContentLocation(0, 0), "test",
SkipSection.EMPTY, randomBoolean() ? Collections.emptyList() : Collections.singletonList(executableSection));

break;
default:
throw new UnsupportedOperationException();
}
ClientYamlTestSuite clientYamlTestSuite = new ClientYamlTestSuite("api", "name", setupSection, teardownSection,
return new ClientYamlTestSuite("api", "name", setupSection, teardownSection,
Collections.singletonList(clientYamlTestSection));
clientYamlTestSuite.validate();
}
}
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,6 +1,7 @@
---
setup:

- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,3 +1,6 @@
setup:
- skip:
features: headers
---
"Test NDJSON file structure analysis without overrides":
- do:
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,3 +1,6 @@
setup:
- skip:
features: headers
---
"Test CRUD on two jobs in shared index":

Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
Expand Up @@ -399,6 +399,8 @@

---
"Test cannot decrease model_memory_limit below current usage":
- skip:
features: headers
- do:
xpack.ml.put_job:
job_id: jobs-crud-model-memory-limit-decrease
Expand Down Expand Up @@ -527,7 +529,8 @@

---
"Test close job":

- skip:
features: headers
- do:
xpack.ml.put_job:
job_id: jobs-crud-close-job
Expand Down Expand Up @@ -762,7 +765,8 @@

---
"Test force close job":

- skip:
features: headers
- do:
xpack.ml.put_job:
job_id: jobs-crud-force-close-job
Expand Down Expand Up @@ -929,7 +933,8 @@

---
"Test cannot create job with existing result document":

- skip:
features: headers
- do:
headers:
Content-Type: application/json
Expand Down Expand Up @@ -1068,7 +1073,8 @@

---
"Test max model memory limit":

- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down Expand Up @@ -1315,7 +1321,8 @@

---
"Test open job when persistent task allocation disabled":

- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,4 +1,6 @@
setup:
- skip:
features: headers
- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
Expand Down
@@ -1,3 +1,6 @@
setup:
- skip:
features: headers
---
"Test new fields are mapped as keyword":

Expand Down