|
59 | 59 | /** |
60 | 60 | * Runs a suite of yaml tests shared with all the official Elasticsearch |
61 | 61 | * clients against an elasticsearch cluster. |
62 | | - * |
| 62 | + * <p> |
63 | 63 | * The suite timeout is extended to account for projects with a large number of tests. |
| 64 | + * </p> |
64 | 65 | */ |
65 | 66 | @TimeoutSuite(millis = 30 * TimeUnits.MINUTE) |
66 | 67 | public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { |
@@ -91,11 +92,11 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { |
91 | 92 | /** |
92 | 93 | * This separator pattern matches ',' except it is preceded by a '\'. |
93 | 94 | * This allows us to support ',' within paths when it is escaped with a slash. |
94 | | - * |
| 95 | + * <p> |
95 | 96 | * 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> |
97 | 98 | * For reference, this regular expression feature is known as zero-width negative look-behind. |
98 | | - * |
| 99 | + * </p> |
99 | 100 | */ |
100 | 101 | private static final String PATHS_SEPARATOR = "(?<!\\\\),"; |
101 | 102 |
|
@@ -226,57 +227,74 @@ public static Iterable<Object[]> createParameters() throws Exception { |
226 | 227 | * Create parameters for this parameterized test. |
227 | 228 | */ |
228 | 229 | public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry) throws Exception { |
229 | | - return createParameters(executeableSectionRegistry, null); |
| 230 | + return createParameters(executeableSectionRegistry, Map.of(), resolvePathsProperty(REST_TESTS_SUITE, "")); |
230 | 231 | } |
231 | 232 |
|
232 | 233 | /** |
233 | 234 | * Create parameters for this parameterized test. |
| 235 | + * @param yamlParameters map or parameters used within the yaml specs to be replaced at parsing time. |
234 | 236 | */ |
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, "")); |
237 | 239 | } |
238 | 240 |
|
239 | 241 | /** |
240 | 242 | * 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. |
241 | 245 | */ |
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); |
244 | 262 | } |
245 | 263 |
|
246 | 264 | /** |
247 | 265 | * Create parameters for this parameterized test. |
248 | 266 | * |
249 | 267 | * @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. |
251 | 269 | * @return list of test candidates. |
252 | | - * @throws Exception |
253 | 270 | */ |
254 | | - public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry, String[] testPaths) |
| 271 | + public static Iterable<Object[]> createParameters(NamedXContentRegistry executeableSectionRegistry, String... testPaths) |
255 | 272 | 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); |
257 | 277 | } |
258 | 278 |
|
259 | 279 | /** |
260 | 280 | * Create parameters for this parameterized test. |
261 | 281 | * |
262 | 282 | * @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. |
265 | 285 | * @return list of test candidates. |
266 | | - * @throws Exception |
267 | 286 | */ |
268 | 287 | public static Iterable<Object[]> createParameters( |
269 | 288 | NamedXContentRegistry executeableSectionRegistry, |
270 | | - String[] testPaths, |
271 | | - Map<String, ?> yamlParameters |
| 289 | + Map<String, ?> yamlParameters, |
| 290 | + String... testPaths |
272 | 291 | ) 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"); |
275 | 295 | } |
276 | 296 |
|
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); |
280 | 298 | List<ClientYamlTestSuite> suites = new ArrayList<>(); |
281 | 299 | IllegalArgumentException validationException = null; |
282 | 300 | // yaml suites are grouped by directory (effectively by api) |
|
0 commit comments