Skip to content

Commit 512272b

Browse files
committed
fix sort and string processor tests around targetField
Tests were randomly assigning `targetField` to an existing field that was an array, causing path resolution issues. This PR fixes those tests Closes #25346 & #25348
1 parent 343e757 commit 512272b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/AbstractStringProcessorTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public void testNonStringValueWithIgnoreMissing() throws Exception {
103103
}
104104

105105
public void testTargetField() throws Exception {
106-
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
106+
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
107107
String fieldValue = RandomDocumentPicks.randomString(random());
108108
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, modifyInput(fieldValue));
109-
String targetFieldName = RandomDocumentPicks.randomFieldName(random());
109+
String targetFieldName = fieldName + "foo";
110110
Processor processor = newProcessor(fieldName, randomBoolean(), targetFieldName);
111111
processor.execute(ingestDocument);
112112
assertThat(ingestDocument.getFieldValue(targetFieldName, String.class), equalTo(expectedResult(fieldValue)));

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/SortProcessorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public void testSortNullValue() throws Exception {
276276
}
277277

278278
public void testDescendingSortWithTargetField() throws Exception {
279-
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
279+
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
280280
int numItems = randomIntBetween(1, 10);
281281
List<String> fieldValue = new ArrayList<>(numItems);
282282
List<String> expectedResult = new ArrayList<>(numItems);
@@ -289,15 +289,15 @@ public void testDescendingSortWithTargetField() throws Exception {
289289
Collections.sort(expectedResult, Collections.reverseOrder());
290290

291291
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
292-
String targetFieldName = RandomDocumentPicks.randomFieldName(random());
292+
String targetFieldName = fieldName + "foo";
293293
Processor processor = new SortProcessor(randomAlphaOfLength(10), fieldName,
294294
SortOrder.DESCENDING, targetFieldName);
295295
processor.execute(ingestDocument);
296296
assertEquals(ingestDocument.getFieldValue(targetFieldName, List.class), expectedResult);
297297
}
298298

299299
public void testAscendingSortWithTargetField() throws Exception {
300-
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
300+
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
301301
int numItems = randomIntBetween(1, 10);
302302
List<String> fieldValue = new ArrayList<>(numItems);
303303
List<String> expectedResult = new ArrayList<>(numItems);
@@ -310,15 +310,15 @@ public void testAscendingSortWithTargetField() throws Exception {
310310
Collections.sort(expectedResult);
311311

312312
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
313-
String targetFieldName = RandomDocumentPicks.randomFieldName(random());
313+
String targetFieldName = fieldName + "foo";
314314
Processor processor = new SortProcessor(randomAlphaOfLength(10), fieldName,
315315
SortOrder.ASCENDING, targetFieldName);
316316
processor.execute(ingestDocument);
317317
assertEquals(ingestDocument.getFieldValue(targetFieldName, List.class), expectedResult);
318318
}
319319

320320
public void testSortWithTargetFieldLeavesOriginalUntouched() throws Exception {
321-
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
321+
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
322322
List<Integer> fieldValue = Arrays.asList(1, 5, 4);
323323
List<Integer> expectedResult = new ArrayList<>(fieldValue);
324324
Collections.sort(expectedResult);

0 commit comments

Comments
 (0)