Skip to content

Commit c2160bb

Browse files
Drop duplicated test cases and fix flaky-ness caused by quoting
1 parent 6cdbf5a commit c2160bb

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,12 @@ public void testStringAsIndexPattern() {
488488
clusterAndIndexAsIndexPattern(command, "cluster:index");
489489
clusterAndIndexAsIndexPattern(command, "cluster:.index");
490490
clusterAndIndexAsIndexPattern(command, "cluster*:index*");
491-
// clusterAndIndexAsIndexPattern(command, "cluster*:<logstash-{now/D}>*");// this is not a valid pattern, * should be inside <>
492-
// clusterAndIndexAsIndexPattern(command, "cluster*:<logstash-{now/D}*>");
493491
clusterAndIndexAsIndexPattern(command, "cluster*:*");
494492
clusterAndIndexAsIndexPattern(command, "*:index*");
495493
clusterAndIndexAsIndexPattern(command, "*:*");
496494
if (EsqlCapabilities.Cap.INDEX_COMPONENT_SELECTORS.isEnabled()) {
497495
assertStringAsIndexPattern("foo::data", command + " foo::data");
498496
assertStringAsIndexPattern("foo::failures", command + " foo::failures");
499-
// assertStringAsIndexPattern("cluster:foo::failures", command + " cluster:\"foo::failures\"");
500497
assertStringAsIndexPattern("*,-foo::data", command + " *, \"-foo\"::data");
501498
assertStringAsIndexPattern("*,-foo::data", command + " *, \"-foo::data\"");
502499
assertStringAsIndexPattern("*::data", command + " *::data");
@@ -3113,25 +3110,21 @@ public void testInvalidPatternsWithIntermittentQuotes() {
31133110
// 1. Quoting the entire pattern.
31143111
// 2. Quoting the cluster alias - "invalid cluster alias":<rest of the pattern>
31153112
// 3. Quoting the index name - <cluster alias>:"invalid index"
3113+
//
3114+
// Note that in these tests, we unquote a pattern and then quote it immediately.
3115+
// This is because when randomly generating an index pattern, it may look like: "foo"::data.
3116+
// To convert it into a quoted string like "foo::data", we need to unquote and then re-quote it.
31163117

31173118
// Prohibited char in a quoted cross cluster index pattern should result in an error.
31183119
{
3119-
var firstValidIndexPattern = randomIndexPattern();
3120-
// Exclude date math expressions or its parsing might result in an error when an invalid char is sneaked in.
3121-
var secondRandomIndex = unquoteIndexPattern(randomIndexPattern(without(DATE_MATH), without(INDEX_SELECTOR)));
3122-
3120+
var randomIndex = randomIndexPattern();
31233121
// Select an invalid char to sneak in.
3124-
char[] invalidChars = { ' ', '\"', '*', ',', '/', '<', '>', '?', '|' };
3122+
char[] invalidChars = { ' ', '/', '<', '>', '?', '|' };
31253123
var randomInvalidChar = invalidChars[randomIntBetween(0, invalidChars.length - 1)];
31263124

3127-
// Find a random position to insert the invalid char.
3128-
var randomPos = randomIntBetween(3, secondRandomIndex.length() - 1);
31293125
// Construct the new invalid index pattern.
3130-
var remoteIndexWithInvalidChar = quote(
3131-
secondRandomIndex.substring(0, randomPos) + randomInvalidChar + secondRandomIndex.substring(randomPos + 1)
3132-
);
3133-
3134-
var query = "FROM " + firstValidIndexPattern + "," + remoteIndexWithInvalidChar;
3126+
var remoteIndexWithInvalidChar = quote(randomIdentifier() + ":" + "foo" + randomInvalidChar + "bar");
3127+
var query = "FROM " + randomIndex + "," + remoteIndexWithInvalidChar;
31353128
expectError(query, "must not contain the following characters [' ','\"','*',',','/','<','>','?','\\','|']");
31363129
}
31373130

@@ -3144,7 +3137,7 @@ public void testInvalidPatternsWithIntermittentQuotes() {
31443137

31453138
// We do not generate a cross cluster pattern or else we'd be getting a different error (which is tested in
31463139
// the next test).
3147-
var remoteIndex = randomIndexPattern(without(CROSS_CLUSTER));
3140+
var remoteIndex = quote(unquoteIndexPattern(randomIndexPattern(without(CROSS_CLUSTER))));
31483141
// Format: FROM <some index>, "<cluster alias: random string>":<remote index>
31493142
var query = "FROM " + randomIndex + "," + malformedClusterAlias + ":" + remoteIndex;
31503143
expectError(query, "cluster string [" + unquoteIndexPattern(malformedClusterAlias) + "] must not contain ':'");
@@ -3177,9 +3170,7 @@ public void testInvalidPatternsWithIntermittentQuotes() {
31773170

31783171
// If a stream in on a remote and the cluster alias and index pattern are separately quoted, we should
31793172
// still be able to validate it.
3180-
// Note:
3181-
// 1. Invalid selector syntax is covered in a different test.
3182-
// 2. We unquote a pattern and re-quote it to prevent partial quoting of pattern fragments.
3173+
// Note: invalid selector syntax is covered in a different test.
31833174
{
31843175
var fromPattern = randomIndexPattern();
31853176
var malformedIndexSelectorPattern = quote(randomIdentifier())

0 commit comments

Comments
 (0)