mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-18 19:05:06 +00:00
Allow set section in setup section of REST tests (#34678)
This commit enables using a set section in the setup section of REST tests.
This commit is contained in:
parent
7af19b8f81
commit
243335e2ba
@ -347,8 +347,8 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
|
|||||||
|
|
||||||
if (!testCandidate.getSetupSection().isEmpty()) {
|
if (!testCandidate.getSetupSection().isEmpty()) {
|
||||||
logger.debug("start setup test [{}]", testCandidate.getTestPath());
|
logger.debug("start setup test [{}]", testCandidate.getTestPath());
|
||||||
for (DoSection doSection : testCandidate.getSetupSection().getDoSections()) {
|
for (ExecutableSection executableSection : testCandidate.getSetupSection().getExecutableSections()) {
|
||||||
executeSection(doSection);
|
executeSection(executableSection);
|
||||||
}
|
}
|
||||||
logger.debug("end setup test [{}]", testCandidate.getTestPath());
|
logger.debug("end setup test [{}]", testCandidate.getTestPath());
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,14 @@ public class SetupSection {
|
|||||||
|
|
||||||
while (parser.currentToken() != XContentParser.Token.END_ARRAY) {
|
while (parser.currentToken() != XContentParser.Token.END_ARRAY) {
|
||||||
ParserUtils.advanceToFieldName(parser);
|
ParserUtils.advanceToFieldName(parser);
|
||||||
if (!"do".equals(parser.currentName())) {
|
if ("do".equals(parser.currentName())) {
|
||||||
|
setupSection.addDoSection(DoSection.parse(parser));
|
||||||
|
} else if ("set".equals(parser.currentName())) {
|
||||||
|
setupSection.addSetSection(SetSection.parse(parser));
|
||||||
|
} else {
|
||||||
throw new IllegalArgumentException("section [" + parser.currentName() + "] not supported within setup section");
|
throw new IllegalArgumentException("section [" + parser.currentName() + "] not supported within setup section");
|
||||||
}
|
}
|
||||||
|
|
||||||
setupSection.addDoSection(DoSection.parse(parser));
|
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +75,7 @@ public class SetupSection {
|
|||||||
|
|
||||||
private SkipSection skipSection;
|
private SkipSection skipSection;
|
||||||
|
|
||||||
private List<DoSection> doSections = new ArrayList<>();
|
private List<ExecutableSection> executableSections = new ArrayList<>();
|
||||||
|
|
||||||
public SkipSection getSkipSection() {
|
public SkipSection getSkipSection() {
|
||||||
return skipSection;
|
return skipSection;
|
||||||
@ -82,12 +85,16 @@ public class SetupSection {
|
|||||||
this.skipSection = skipSection;
|
this.skipSection = skipSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DoSection> getDoSections() {
|
public List<ExecutableSection> getExecutableSections() {
|
||||||
return doSections;
|
return executableSections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDoSection(DoSection doSection) {
|
public void addDoSection(DoSection doSection) {
|
||||||
this.doSections.add(doSection);
|
this.executableSections.add(doSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSetSection(SetSection setSection) {
|
||||||
|
this.executableSections.add(setSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
|
@ -89,10 +89,13 @@ public class ClientYamlTestSuiteTests extends AbstractClientYamlTestFragmentPars
|
|||||||
if (includeSetup) {
|
if (includeSetup) {
|
||||||
assertThat(restTestSuite.getSetupSection().isEmpty(), equalTo(false));
|
assertThat(restTestSuite.getSetupSection().isEmpty(), equalTo(false));
|
||||||
assertThat(restTestSuite.getSetupSection().getSkipSection().isEmpty(), equalTo(true));
|
assertThat(restTestSuite.getSetupSection().getSkipSection().isEmpty(), equalTo(true));
|
||||||
assertThat(restTestSuite.getSetupSection().getDoSections().size(), equalTo(1));
|
assertThat(restTestSuite.getSetupSection().getExecutableSections().size(), equalTo(1));
|
||||||
assertThat(restTestSuite.getSetupSection().getDoSections().get(0).getApiCallSection().getApi(), equalTo("indices.create"));
|
final ExecutableSection maybeDoSection = restTestSuite.getSetupSection().getExecutableSections().get(0);
|
||||||
assertThat(restTestSuite.getSetupSection().getDoSections().get(0).getApiCallSection().getParams().size(), equalTo(1));
|
assertThat(maybeDoSection, instanceOf(DoSection.class));
|
||||||
assertThat(restTestSuite.getSetupSection().getDoSections().get(0).getApiCallSection().getParams().get("index"),
|
final DoSection doSection = (DoSection) maybeDoSection;
|
||||||
|
assertThat(doSection.getApiCallSection().getApi(), equalTo("indices.create"));
|
||||||
|
assertThat(doSection.getApiCallSection().getParams().size(), equalTo(1));
|
||||||
|
assertThat(doSection.getApiCallSection().getParams().get("index"),
|
||||||
equalTo("test_index"));
|
equalTo("test_index"));
|
||||||
} else {
|
} else {
|
||||||
assertThat(restTestSuite.getSetupSection().isEmpty(), equalTo(true));
|
assertThat(restTestSuite.getSetupSection().isEmpty(), equalTo(true));
|
||||||
|
@ -21,7 +21,12 @@ package org.elasticsearch.test.rest.yaml.section;
|
|||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.hasKey;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
public class SetupSectionTests extends AbstractClientYamlTestFragmentParserTestCase {
|
public class SetupSectionTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||||
@ -45,9 +50,48 @@ public class SetupSectionTests extends AbstractClientYamlTestFragmentParserTestC
|
|||||||
|
|
||||||
assertThat(setupSection, notNullValue());
|
assertThat(setupSection, notNullValue());
|
||||||
assertThat(setupSection.getSkipSection().isEmpty(), equalTo(true));
|
assertThat(setupSection.getSkipSection().isEmpty(), equalTo(true));
|
||||||
assertThat(setupSection.getDoSections().size(), equalTo(2));
|
assertThat(setupSection.getExecutableSections().size(), equalTo(2));
|
||||||
assertThat(setupSection.getDoSections().get(0).getApiCallSection().getApi(), equalTo("index1"));
|
assertThat(setupSection.getExecutableSections().get(0), instanceOf(DoSection.class));
|
||||||
assertThat(setupSection.getDoSections().get(1).getApiCallSection().getApi(), equalTo("index2"));
|
assertThat(((DoSection)setupSection.getExecutableSections().get(0)).getApiCallSection().getApi(), equalTo("index1"));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(1), instanceOf(DoSection.class));
|
||||||
|
assertThat(((DoSection)setupSection.getExecutableSections().get(1)).getApiCallSection().getApi(), equalTo("index2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testParseSetSectionInSetupSection() throws IOException {
|
||||||
|
parser = createParser(YamlXContent.yamlXContent,
|
||||||
|
"- do:\n" +
|
||||||
|
" cluster.state: {}\n" +
|
||||||
|
"- set: { master_node: master }\n" +
|
||||||
|
"- do:\n" +
|
||||||
|
" nodes.info:\n" +
|
||||||
|
" metric: [ http, transport ]\n" +
|
||||||
|
"- set: {nodes.$master.http.publish_address: host}\n" +
|
||||||
|
"- set: {nodes.$master.transport.publish_address: transport_host}\n");
|
||||||
|
|
||||||
|
final SetupSection setupSection = SetupSection.parse(parser);
|
||||||
|
|
||||||
|
assertNotNull(setupSection);
|
||||||
|
assertTrue(setupSection.getSkipSection().isEmpty());
|
||||||
|
assertThat(setupSection.getExecutableSections().size(), equalTo(5));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(0), instanceOf(DoSection.class));
|
||||||
|
assertThat(((DoSection)setupSection.getExecutableSections().get(0)).getApiCallSection().getApi(), equalTo("cluster.state"));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(1), instanceOf(SetSection.class));
|
||||||
|
final SetSection firstSetSection = (SetSection)setupSection.getExecutableSections().get(1);
|
||||||
|
assertThat(firstSetSection.getStash().entrySet(), hasSize(1));
|
||||||
|
assertThat(firstSetSection.getStash(), hasKey("master_node"));
|
||||||
|
assertThat(firstSetSection.getStash().get("master_node"), equalTo("master"));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(2), instanceOf(DoSection.class));
|
||||||
|
assertThat(((DoSection)setupSection.getExecutableSections().get(2)).getApiCallSection().getApi(), equalTo("nodes.info"));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(3), instanceOf(SetSection.class));
|
||||||
|
final SetSection secondSetSection = (SetSection)setupSection.getExecutableSections().get(3);
|
||||||
|
assertThat(secondSetSection.getStash().entrySet(), hasSize(1));
|
||||||
|
assertThat(secondSetSection.getStash(), hasKey("nodes.$master.http.publish_address"));
|
||||||
|
assertThat(secondSetSection.getStash().get("nodes.$master.http.publish_address"), equalTo("host"));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(4), instanceOf(SetSection.class));
|
||||||
|
final SetSection thirdSetSection = (SetSection)setupSection.getExecutableSections().get(4);
|
||||||
|
assertThat(thirdSetSection.getStash().entrySet(), hasSize(1));
|
||||||
|
assertThat(thirdSetSection.getStash(), hasKey("nodes.$master.transport.publish_address"));
|
||||||
|
assertThat(thirdSetSection.getStash().get("nodes.$master.transport.publish_address"), equalTo("transport_host"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseSetupAndSkipSectionNoSkip() throws Exception {
|
public void testParseSetupAndSkipSectionNoSkip() throws Exception {
|
||||||
@ -78,8 +122,10 @@ public class SetupSectionTests extends AbstractClientYamlTestFragmentParserTestC
|
|||||||
assertThat(setupSection.getSkipSection().getUpperVersion(),
|
assertThat(setupSection.getSkipSection().getUpperVersion(),
|
||||||
equalTo(Version.V_6_3_0));
|
equalTo(Version.V_6_3_0));
|
||||||
assertThat(setupSection.getSkipSection().getReason(), equalTo("Update doesn't return metadata fields, waiting for #3259"));
|
assertThat(setupSection.getSkipSection().getReason(), equalTo("Update doesn't return metadata fields, waiting for #3259"));
|
||||||
assertThat(setupSection.getDoSections().size(), equalTo(2));
|
assertThat(setupSection.getExecutableSections().size(), equalTo(2));
|
||||||
assertThat(setupSection.getDoSections().get(0).getApiCallSection().getApi(), equalTo("index1"));
|
assertThat(setupSection.getExecutableSections().get(0), instanceOf(DoSection.class));
|
||||||
assertThat(setupSection.getDoSections().get(1).getApiCallSection().getApi(), equalTo("index2"));
|
assertThat(((DoSection)setupSection.getExecutableSections().get(0)).getApiCallSection().getApi(), equalTo("index1"));
|
||||||
|
assertThat(setupSection.getExecutableSections().get(1), instanceOf(DoSection.class));
|
||||||
|
assertThat(((DoSection)setupSection.getExecutableSections().get(1)).getApiCallSection().getApi(), equalTo("index2"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user