Fix #12854: Executable TestSuite should inherit the ownership from its table (#14612)

This commit is contained in:
Sriharsha Chintalapani 2024-01-08 08:24:37 -08:00 committed by GitHub
parent e8eb2bda3c
commit dcff230bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 12 deletions

View File

@ -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;
@ -53,6 +55,15 @@ public class TestSuiteRepository extends EntityRepository<TestSuite> {
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);

View File

@ -378,7 +378,6 @@ public class TestSuiteResource extends EntityResource<TestSuite, TestSuiteReposi
@Valid CreateTestSuite create) {
TestSuite testSuite = getTestSuite(create, securityContext.getUserPrincipal().getName());
testSuite.setExecutable(true);
testSuite = setExecutableTestSuiteOwner(testSuite);
return create(uriInfo, securityContext, testSuite);
}
@ -653,15 +652,4 @@ public class TestSuiteResource extends EntityResource<TestSuite, TestSuiteReposi
}
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);
}
}

View File

@ -42,6 +42,7 @@ import org.openmetadata.schema.type.Include;
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;
@ -162,6 +163,36 @@ public class TestSuiteResourceTest extends EntityResourceTest<TestSuite, CreateT
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();