Skip to content

Commit d392312

Browse files
authored
Make ESClientYamlSuiteTestCase#createParameters paths argument variadic (elastic#133477)
1 parent 1091595 commit d392312

File tree

12 files changed

+52
-34
lines changed

12 files changed

+52
-34
lines changed

modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class RepositoryS3ClientYamlTestSuiteIT extends AbstractRepositoryS3Clien
5252

5353
@ParametersFactory
5454
public static Iterable<Object[]> parameters() throws Exception {
55-
return createParameters(new String[] { "repository_s3/10_basic", "repository_s3/20_repository_permanent_credentials" });
55+
return createParameters("repository_s3/10_basic", "repository_s3/20_repository_permanent_credentials");
5656
}
5757

5858
public RepositoryS3ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3RegionalStsClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static Iterable<Object[]> parameters() throws Exception {
3737
// Run just the basic sanity test to make sure ES starts up and loads the S3 repository with a regional endpoint without an error.
3838
// It would be great to make actual requests against a test fixture, but setting the region means using a production endpoint.
3939
// See #102230 for more details.
40-
return createParameters(new String[] { "repository_s3/10_basic" });
40+
return createParameters("repository_s3/10_basic");
4141
}
4242

4343
public RepositoryS3RegionalStsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ protected String getTestRestCluster() {
5252

5353
@ParametersFactory
5454
public static Iterable<Object[]> parameters() throws Exception {
55-
return createParameters(new String[] { "hdfs_repository" }, Map.of("hdfs_port", hdfsFixture.getPort()));
55+
return createParameters(Map.of("hdfs_port", hdfsFixture.getPort()), "hdfs_repository");
5656
}
5757
}

plugins/repository-hdfs/src/yamlRestTest/java/org/elasticsearch/repositories/hdfs/SecureRepositoryHdfsClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ protected String getTestRestCluster() {
5858

5959
@ParametersFactory
6060
public static Iterable<Object[]> parameters() throws Exception {
61-
return createParameters(new String[] { "secure_hdfs_repository" }, Map.of("secure_hdfs_port", hdfsFixture.getPort()));
61+
return createParameters(Map.of("secure_hdfs_port", hdfsFixture.getPort()), "secure_hdfs_repository");
6262
}
6363
}

test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
/**
6060
* Runs a suite of yaml tests shared with all the official Elasticsearch
6161
* clients against an elasticsearch cluster.
62-
*
62+
* <p>
6363
* The suite timeout is extended to account for projects with a large number of tests.
64+
* </p>
6465
*/
6566
@TimeoutSuite(millis = 30 * TimeUnits.MINUTE)
6667
public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
@@ -91,11 +92,11 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
9192
/**
9293
* This separator pattern matches ',' except it is preceded by a '\'.
9394
* This allows us to support ',' within paths when it is escaped with a slash.
94-
*
95+
* <p>
9596
* For example, the path string "/a/b/c\,d/e/f,/foo/bar,/baz" is separated to "/a/b/c\,d/e/f", "/foo/bar" and "/baz".
96-
*
97+
* </p><p>
9798
* For reference, this regular expression feature is known as zero-width negative look-behind.
98-
*
99+
* </p>
99100
*/
100101
private static final String PATHS_SEPARATOR = "(?<!\\\\),";
101102

@@ -226,57 +227,74 @@ public static Iterable<Object[]> createParameters() throws Exception {
226227
* Create parameters for this parameterized test.
227228
*/
228229
public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry) throws Exception {
229-
return createParameters(executeableSectionRegistry, null);
230+
return createParameters(executeableSectionRegistry, Map.of(), resolvePathsProperty(REST_TESTS_SUITE, ""));
230231
}
231232

232233
/**
233234
* Create parameters for this parameterized test.
235+
* @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time.
234236
*/
235-
public static Iterable<Object[]> createParameters(String[] testPaths, Map<String, Object> yamlParameters) throws Exception {
236-
return createParameters(ExecutableSection.XCONTENT_REGISTRY, testPaths, yamlParameters);
237+
public static Iterable<Object[]> createParameters(Map<String, Object> yamlParameters) throws Exception {
238+
return createParameters(ExecutableSection.XCONTENT_REGISTRY, yamlParameters, resolvePathsProperty(REST_TESTS_SUITE, ""));
237239
}
238240

239241
/**
240242
* Create parameters for this parameterized test.
243+
* @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time.
244+
* @param testPaths list of paths to explicitly search for tests.
241245
*/
242-
public static Iterable<Object[]> createParameters(String[] testPaths) throws Exception {
243-
return createParameters(testPaths, Collections.emptyMap());
246+
public static Iterable<Object[]> createParameters(Map<String, Object> yamlParameters, String... testPaths) throws Exception {
247+
if (System.getProperty(REST_TESTS_SUITE) != null) {
248+
throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths.");
249+
}
250+
return createParameters(ExecutableSection.XCONTENT_REGISTRY, yamlParameters, testPaths);
251+
}
252+
253+
/**
254+
* Create parameters for this parameterized test.
255+
* @param testPaths list of paths to explicitly search for tests.
256+
*/
257+
public static Iterable<Object[]> createParameters(String... testPaths) throws Exception {
258+
if (System.getProperty(REST_TESTS_SUITE) != null) {
259+
throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths.");
260+
}
261+
return createParameters(ExecutableSection.XCONTENT_REGISTRY, Map.of(), testPaths);
244262
}
245263

246264
/**
247265
* Create parameters for this parameterized test.
248266
*
249267
* @param executeableSectionRegistry registry of executable sections
250-
* @param testPaths list of paths to explicitly search for tests. If <code>null</code> then include all tests in root path.
268+
* @param testPaths list of paths to explicitly search for tests.
251269
* @return list of test candidates.
252-
* @throws Exception
253270
*/
254-
public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry, String[] testPaths)
271+
public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry, String... testPaths)
255272
throws Exception {
256-
return createParameters(executeableSectionRegistry, testPaths, Collections.emptyMap());
273+
if (System.getProperty(REST_TESTS_SUITE) != null) {
274+
throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths.");
275+
}
276+
return createParameters(executeableSectionRegistry, Map.of(), testPaths);
257277
}
258278

259279
/**
260280
* Create parameters for this parameterized test.
261281
*
262282
* @param executeableSectionRegistry registry of executable sections
263-
* @param testPaths list of paths to explicitly search for tests. If <code>null</code> then include all tests in root path.
264-
* @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time.
283+
* @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time.
284+
* @param testPaths list of paths to explicitly search for tests. If {@code null} then include all tests in root path.
265285
* @return list of test candidates.
266-
* @throws Exception
267286
*/
268287
public static Iterable<Object[]> createParameters(
269288
NamedXContentRegistry executeableSectionRegistry,
270-
String[] testPaths,
271-
Map<String, ?> yamlParameters
289+
Map<String, ?> yamlParameters,
290+
String... testPaths
272291
) throws Exception {
273-
if (testPaths != null && System.getProperty(REST_TESTS_SUITE) != null) {
274-
throw new IllegalArgumentException("The '" + REST_TESTS_SUITE + "' system property is not supported with explicit test paths.");
292+
293+
if (testPaths == null) {
294+
throw new IllegalArgumentException("testPaths cannot be null");
275295
}
276296

277-
// default to all tests under the test root
278-
String[] paths = testPaths == null ? resolvePathsProperty(REST_TESTS_SUITE, "") : testPaths;
279-
Map<String, Set<Path>> yamlSuites = loadSuites(paths);
297+
Map<String, Set<Path>> yamlSuites = loadSuites(testPaths);
280298
List<ClientYamlTestSuite> suites = new ArrayList<>();
281299
IllegalArgumentException validationException = null;
282300
// yaml suites are grouped by directory (effectively by api)

x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleRestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public DownsampleRestIT(final ClientYamlTestCandidate testCandidate) {
3535

3636
@ParametersFactory
3737
public static Iterable<Object[]> parameters() throws Exception {
38-
return ESClientYamlSuiteTestCase.createParameters(new String[] { "downsample" });
38+
return ESClientYamlSuiteTestCase.createParameters("downsample");
3939
}
4040

4141
}

x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithBasicRestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public DownsampleWithBasicRestIT(final ClientYamlTestCandidate testCandidate) {
3434

3535
@ParametersFactory
3636
public static Iterable<Object[]> parameters() throws Exception {
37-
return ESClientYamlSuiteTestCase.createParameters(new String[] { "downsample" });
37+
return ESClientYamlSuiteTestCase.createParameters("downsample");
3838
}
3939

4040
}

x-pack/plugin/downsample/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/downsample/DownsampleWithSecurityRestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ protected Settings restClientSettings() {
4848

4949
@ParametersFactory
5050
public static Iterable<Object[]> parameters() throws Exception {
51-
return ESClientYamlSuiteTestCase.createParameters(new String[] { "downsample-with-security" });
51+
return ESClientYamlSuiteTestCase.createParameters("downsample-with-security");
5252
}
5353
}

x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LicenseClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public LicenseClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCa
3333

3434
@ParametersFactory
3535
public static Iterable<Object[]> parameters() throws Exception {
36-
return ESClientYamlSuiteTestCase.createParameters(new String[] { "license" });
36+
return ESClientYamlSuiteTestCase.createParameters("license");
3737
}
3838

3939
@Override

x-pack/plugin/rank-rrf/src/yamlRestTest/java/org/elasticsearch/xpack/rank/rrf/LinearRankClientYamlTestSuiteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public LinearRankClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate tes
4040

4141
@ParametersFactory
4242
public static Iterable<Object[]> parameters() throws Exception {
43-
return ESClientYamlSuiteTestCase.createParameters(new String[] { "linear" });
43+
return ESClientYamlSuiteTestCase.createParameters("linear");
4444
}
4545

4646
@Override

0 commit comments

Comments
 (0)