Skip to content

Commit 9335566

Browse files
authored
Add default parameter supplier conversor for function tests (#109969)
Continuation of #109207 (review) - Added a new function with the function test default generators (+ that PR BytesRef modifier) - Applied it in all _trivial_ places. That is, where those same functions were being used The idea here is to be able to easily add extra "test generators" without having to touch everything. As a next step, we could try to apply them to the remaining functions, and for cases where some testcases don't make sense, add some kind of "disableModifiers={a, b}" parameter. This way, we would declare exclusions instead of inclusions, which is safer.
1 parent 239eb9e commit 9335566

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+263
-263
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ protected static Iterable<Object[]> parameterSuppliersFromTypedData(List<TestCas
161161
return parameters;
162162
}
163163

164+
/**
165+
* Converts a list of test cases into a list of parameter suppliers.
166+
* Also, adds a default set of extra test cases.
167+
* <p>
168+
* Use if possible, as this method may get updated with new checks in the future.
169+
* </p>
170+
*
171+
* @param entirelyNullPreservesType See {@link #anyNullIsNull(boolean, List)}
172+
*/
173+
protected static Iterable<Object[]> parameterSuppliersFromTypedDataWithDefaultChecks(
174+
boolean entirelyNullPreservesType,
175+
List<TestCaseSupplier> suppliers
176+
) {
177+
return parameterSuppliersFromTypedData(
178+
errorsForCasesWithoutExamples(anyNullIsNull(entirelyNullPreservesType, randomizeBytesRefsOffset(suppliers)))
179+
);
180+
}
181+
164182
/**
165183
* Build an {@link Attribute} that loads a field.
166184
*/

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/FromBase64Tests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static Iterable<Object[]> parameters() {
5555
);
5656
}));
5757

58-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
58+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
5959
}
6060

6161
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToBase64Tests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static Iterable<Object[]> parameters() {
5555
);
5656
}));
5757

58-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
58+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
5959
}
6060

6161
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToBooleanTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static Iterable<Object[]> parameters() {
8080
emptyList()
8181
);
8282

83-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
83+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
8484
}
8585

8686
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToCartesianPointTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Iterable<Object[]> parameters() {
7272
);
7373
}
7474

75-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
75+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
7676
}
7777

7878
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToCartesianShapeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static Iterable<Object[]> parameters() {
7373
);
7474
}
7575

76-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
76+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
7777
}
7878

7979
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDatetimeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static Iterable<Object[]> parameters() {
162162
)
163163
);
164164

165-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
165+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
166166
}
167167

168168
private static String randomDateString(long from, long to) {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDegreesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static Iterable<Object[]> parameters() {
8989
)
9090
);
9191

92-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
92+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
9393
}
9494

9595
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDoubleTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static Iterable<Object[]> parameters() {
139139
List.of()
140140
);
141141

142-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
142+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
143143
}
144144

145145
@Override

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToGeoPointTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static Iterable<Object[]> parameters() {
6666
);
6767
}
6868

69-
return parameterSuppliersFromTypedData(errorsForCasesWithoutExamples(anyNullIsNull(true, suppliers)));
69+
return parameterSuppliersFromTypedDataWithDefaultChecks(true, suppliers);
7070
}
7171

7272
@Override

0 commit comments

Comments
 (0)