-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix assertIngestDocument wrongfully passing (#31913)
* Fix assertIngestDocument wrongfully passing * Previously docA being subset of docB passed because iteration was over docA's keys only * Scalars in nested fields were not compared in all cases * Assertion errors were hard to interpret (message wasn't correct since it only mentioned the class type) * In cases where two paths contained different types a ClassCastException was thrown instead of an AssertionError * Fixes #28492
- Loading branch information
1 parent
4b8b831
commit b4087d6
Showing
4 changed files
with
123 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
test/framework/src/test/java/org/elasticsearch/ingest/IngestDocumentMatcherTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.ingest; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument; | ||
|
||
public class IngestDocumentMatcherTests extends ESTestCase { | ||
|
||
public void testDifferentMapData() { | ||
Map<String, Object> sourceAndMetadata1 = new HashMap<>(); | ||
sourceAndMetadata1.put("foo", "bar"); | ||
IngestDocument document1 = new IngestDocument(sourceAndMetadata1, new HashMap<>()); | ||
IngestDocument document2 = new IngestDocument(new HashMap<>(), new HashMap<>()); | ||
assertThrowsOnComparision(document1, document2); | ||
} | ||
|
||
public void testDifferentLengthListData() { | ||
String rootKey = "foo"; | ||
IngestDocument document1 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Arrays.asList("bar", "baz")), new HashMap<>()); | ||
IngestDocument document2 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Collections.emptyList()), new HashMap<>()); | ||
assertThrowsOnComparision(document1, document2); | ||
} | ||
|
||
public void testDifferentNestedListFieldData() { | ||
String rootKey = "foo"; | ||
IngestDocument document1 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Arrays.asList("bar", "baz")), new HashMap<>()); | ||
IngestDocument document2 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Arrays.asList("bar", "blub")), new HashMap<>()); | ||
assertThrowsOnComparision(document1, document2); | ||
} | ||
|
||
public void testDifferentNestedMapFieldData() { | ||
String rootKey = "foo"; | ||
IngestDocument document1 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Collections.singletonMap("bar", "baz")), new HashMap<>()); | ||
IngestDocument document2 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Collections.singletonMap("bar", "blub")), new HashMap<>()); | ||
assertThrowsOnComparision(document1, document2); | ||
} | ||
|
||
public void testOnTypeConflict() { | ||
String rootKey = "foo"; | ||
IngestDocument document1 = | ||
new IngestDocument(Collections.singletonMap(rootKey, Collections.singletonList("baz")), new HashMap<>()); | ||
IngestDocument document2 = new IngestDocument( | ||
Collections.singletonMap(rootKey, Collections.singletonMap("blub", "blab")), new HashMap<>() | ||
); | ||
assertThrowsOnComparision(document1, document2); | ||
} | ||
|
||
private static void assertThrowsOnComparision(IngestDocument document1, IngestDocument document2) { | ||
expectThrows(AssertionError.class, () -> assertIngestDocument(document1, document2)); | ||
expectThrows(AssertionError.class, () -> assertIngestDocument(document2, document1)); | ||
} | ||
} |