Skip to content

Commit

Permalink
Fix: test case indexing -- remove changeDescription from testSuites l…
Browse files Browse the repository at this point in the history
…ist (#17083)

* fix: test case indexing -- remove changeDescription from testSuites list

* fix: change type to interface

* style: ran java linting
  • Loading branch information
TeddyCr authored Jul 19, 2024
1 parent bc49f9e commit 13daa36
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
import org.openmetadata.service.search.models.SearchSuggest;

public record TestCaseIndex(TestCase testCase) implements SearchIndex {
private static final Set<String> excludeFields = Set.of("testSuites.changeDescription");
private static final Set<String> excludeFields = Set.of("changeDescription");

@Override
public Object getEntity() {
return testCase;
}

@Override
public Set<String> getExcludedFields() {
return excludeFields;
public void removeNonIndexableFields(Map<String, Object> esDoc) {
SearchIndex.super.removeNonIndexableFields(esDoc);
List<Map<String, Object>> testSuites = (List<Map<String, Object>>) esDoc.get("testSuites");
for (Map<String, Object> testSuite : testSuites) {
SearchIndexUtils.removeNonIndexableFields(testSuite, excludeFields);
}
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import org.openmetadata.service.resources.databases.TableResourceTest;
import org.openmetadata.service.resources.feeds.FeedResourceTest;
import org.openmetadata.service.resources.feeds.MessageParser;
import org.openmetadata.service.search.indexes.TestCaseIndex;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.ResultList;
import org.openmetadata.service.util.TestUtils;
Expand Down Expand Up @@ -2026,6 +2027,30 @@ void wrongMinMaxTestParameter(TestInfo test) throws HttpResponseException {
() -> createEntity(invalidTestCaseMixedTypes, ADMIN_AUTH_HEADERS), BAD_REQUEST, "Value");
}

@Test
void test_testCaseEsDocCleanUp(TestInfo testInfo) {
TestCase testCase =
new TestCase()
.withId(UUID.randomUUID())
.withChangeDescription(new ChangeDescription())
.withTestSuites(
List.of(
new TestSuite()
.withId(UUID.randomUUID())
.withChangeDescription(new ChangeDescription()),
new TestSuite()
.withId(UUID.randomUUID())
.withChangeDescription(new ChangeDescription())));

Map<String, Object> doc = JsonUtils.convertValue(testCase, Map.class);

TestCaseIndex testCaseIndex = new TestCaseIndex(testCase);
testCaseIndex.removeNonIndexableFields(doc);
assertNull(doc.get("changeDescription"));
List<Map<String, Object>> testSuites = (List<Map<String, Object>>) doc.get("testSuites");
assertNull(testSuites.get(0).get("changeDescription"));
}

public void deleteTestCaseResult(String fqn, Long timestamp, Map<String, String> authHeaders)
throws HttpResponseException {
WebTarget target = getCollection().path("/" + fqn + "/testCaseResult/" + timestamp);
Expand Down

0 comments on commit 13daa36

Please sign in to comment.