Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12854: Executable TestSuite should inherit the ownership from it's table #14612

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.openmetadata.service.jdbi3;

import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
import static org.openmetadata.schema.type.Include.ALL;
import static org.openmetadata.service.Entity.TABLE;
import static org.openmetadata.service.Entity.TEST_CASE;
import static org.openmetadata.service.Entity.TEST_SUITE;
import static org.openmetadata.service.util.FullyQualifiedName.quoteName;
Expand Down Expand Up @@ -53,6 +55,15 @@ public void setFields(TestSuite entity, EntityUtil.Fields fields) {
entity.withTests(fields.contains("tests") ? getTestCases(entity) : entity.getTests());
}

@Override
public void setInheritedFields(TestSuite testSuite, EntityUtil.Fields fields) {
if (Boolean.TRUE.equals(testSuite.getExecutable())) {
Table table =
Entity.getEntity(TABLE, testSuite.getExecutableEntityReference().getId(), "owner", ALL);
inheritOwner(testSuite, fields, table);
}
}

@Override
public void clearFields(TestSuite entity, EntityUtil.Fields fields) {
entity.setPipelines(fields.contains("pipelines") ? entity.getPipelines() : null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ public Response createExecutable(
@Valid CreateTestSuite create) {
TestSuite testSuite = getTestSuite(create, securityContext.getUserPrincipal().getName());
testSuite.setExecutable(true);
testSuite = setExecutableTestSuiteOwner(testSuite);
return create(uriInfo, securityContext, testSuite);
}

Expand Down Expand Up @@ -653,15 +652,4 @@ private TestSuite getTestSuite(CreateTestSuite create, String user) {
}
return testSuite;
}

private TestSuite setExecutableTestSuiteOwner(TestSuite testSuite) {
Table tableEntity =
Entity.getEntity(
testSuite.getExecutableEntityReference().getType(),
testSuite.getExecutableEntityReference().getId(),
"owner",
ALL);
EntityReference ownerReference = tableEntity.getOwner();
return testSuite.withOwner(ownerReference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.openmetadata.service.Entity;
import org.openmetadata.service.resources.EntityResourceTest;
import org.openmetadata.service.resources.databases.TableResourceTest;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.ResultList;
import org.openmetadata.service.util.TestUtils;

Expand Down Expand Up @@ -162,6 +163,36 @@ void put_testCaseResults_200() throws IOException, ParseException {
assertEquals(true, deletedTestSuite.getDeleted());
}

@Test
void test_inheritOwnerFromTable(TestInfo test) throws IOException {
TableResourceTest tableResourceTest = new TableResourceTest();
CreateTable tableReq =
tableResourceTest
.createRequest(test)
.withColumns(
List.of(
new Column()
.withName(C1)
.withDisplayName("c1")
.withDataType(ColumnDataType.VARCHAR)
.withDataLength(10)))
.withOwner(USER1_REF);
Table table = tableResourceTest.createEntity(tableReq, ADMIN_AUTH_HEADERS);
table = tableResourceTest.getEntity(table.getId(), "*", ADMIN_AUTH_HEADERS);
CreateTestSuite createExecutableTestSuite = createRequest(table.getFullyQualifiedName());
TestSuite executableTestSuite =
createExecutableTestSuite(createExecutableTestSuite, ADMIN_AUTH_HEADERS);
TestSuite testSuite = getEntity(executableTestSuite.getId(), "*", ADMIN_AUTH_HEADERS);
assertEquals(testSuite.getOwner().getId(), table.getOwner().getId());
Table updateTableOwner = table;
updateTableOwner.setOwner(TEAM11_REF);
tableResourceTest.patchEntity(
table.getId(), JsonUtils.pojoToJson(table), updateTableOwner, ADMIN_AUTH_HEADERS);
table = tableResourceTest.getEntity(table.getId(), "*", ADMIN_AUTH_HEADERS);
testSuite = getEntity(executableTestSuite.getId(), "*", ADMIN_AUTH_HEADERS);
assertEquals(table.getOwner().getId(), testSuite.getOwner().getId());
}

@Test
void post_createLogicalTestSuiteAndAddTests_200(TestInfo test) throws IOException {
TestCaseResourceTest testCaseResourceTest = new TestCaseResourceTest();
Expand Down