Skip to content

Commit 242dbe6

Browse files
committed
Add failing tests
1 parent c134b04 commit 242dbe6

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,59 @@ public void testIgnoreMissing() throws Exception {
6666
processor.execute(document);
6767
}
6868

69+
public void testIgnoreMissingAndNullInPath() throws Exception {
70+
Map<String, Object> source = new HashMap<>();
71+
Map<String, Object> some = new HashMap<>();
72+
Map<String, Object> map = new HashMap<>();
73+
Map<String, Object> path = new HashMap<>();
74+
75+
switch (randomIntBetween(0, 6)) {
76+
case 0 -> {
77+
// empty source
78+
}
79+
case 1 -> {
80+
source.put("some", null);
81+
}
82+
case 2 -> {
83+
some.put("map", null);
84+
source.put("some", some);
85+
}
86+
case 3 -> {
87+
some.put("map", map);
88+
source.put("some", some);
89+
}
90+
case 4 -> {
91+
map.put("path", null);
92+
some.put("map", map);
93+
source.put("some", some);
94+
}
95+
case 5 -> {
96+
map.put("path", path);
97+
some.put("map", map);
98+
source.put("some", some);
99+
}
100+
case 6 -> {
101+
map.put("path", "foobar");
102+
some.put("map", map);
103+
source.put("some", some);
104+
}
105+
}
106+
107+
if (randomBoolean()) {
108+
source.put("some", null);
109+
} else {
110+
some.put("map", null);
111+
source.put("some", some);
112+
}
113+
IngestDocument document = RandomDocumentPicks.randomIngestDocument(random(), source);
114+
Map<String, Object> config = new HashMap<>();
115+
config.put("field", "some.map.path");
116+
config.put("ignore_missing", true);
117+
Processor processor = new RemoveProcessor.Factory(TestTemplateService.instance()).create(null, null, null, config, null);
118+
processor.execute(document);
119+
assertThat(document.hasField("some.map.path"), is(false));
120+
}
121+
69122
public void testKeepFields() throws Exception {
70123
Map<String, Object> address = new HashMap<>();
71124
address.put("street", "Ipiranga Street");

server/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,14 @@ public void testRemoveFieldIgnoreMissing() {
860860

861861
// if ignoreMissing is false, we throw an exception for values that aren't found
862862
IllegalArgumentException e;
863-
e = expectThrows(IllegalArgumentException.class, () -> document.removeField("fizz.some.nonsense", false));
864-
assertThat(e.getMessage(), is("field [some] not present as part of path [fizz.some.nonsense]"));
863+
if (randomBoolean()) {
864+
document.setFieldValue("fizz.some", (Object) null);
865+
e = expectThrows(IllegalArgumentException.class, () -> document.removeField("fizz.some.nonsense", false));
866+
assertThat(e.getMessage(), is("cannot remove [nonsense] from null as part of path [fizz.some.nonsense]"));
867+
} else {
868+
e = expectThrows(IllegalArgumentException.class, () -> document.removeField("fizz.some.nonsense", false));
869+
assertThat(e.getMessage(), is("field [some] not present as part of path [fizz.some.nonsense]"));
870+
}
865871

866872
// but no exception is thrown if ignoreMissing is true
867873
document.removeField("fizz.some.nonsense", true);

0 commit comments

Comments
 (0)