jerryshao commented on code in PR #13478:
URL: https://github.com/apache/gravitino/pull/13478#discussion_r4236275573
##########
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:
##########
@@ -483,6 +483,73 @@ public void testCreateUpdateAndGetRowFilterPolicy() {
Assertions.assertEquals(updatedContent, updated.content());
Assertions.assertEquals(
updatedContent, policyManager.getPolicy(METALAKE,
policyName).content());
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.createPolicy(
+ METALAKE,
+ "invalid_" + policyName,
+ Policy.BuiltInType.ROW_FILTER,
+ null,
+ true,
+ PolicyContents.rowFilter("filter := col(\"region\")")));
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.alterPolicy(
+ METALAKE,
+ policyName,
+ PolicyChange.updateContent(
+ "system_row_filter",
+ PolicyContents.rowFilter("mask :=
action(\"replace-with-null\")"))));
+ Assertions.assertEquals(
+ updatedContent, policyManager.getPolicy(METALAKE,
policyName).content());
+ }
+
+ @Test
+ public void testCreateUpdateAndGetColumnMaskPolicy() {
+ String policyName = "column_mask_" +
UUID.randomUUID().toString().replace("-", "");
+ PolicyContent originalContent = PolicyContents.columnMask("mask :=
action(\"show-last-4\")");
+
+ PolicyEntity created =
+ policyManager.createPolicy(
+ METALAKE, policyName, Policy.BuiltInType.COLUMN_MASK, null, true,
originalContent);
+
+ Assertions.assertEquals(originalContent, created.content());
+ Assertions.assertEquals(
+ originalContent, policyManager.getPolicy(METALAKE,
policyName).content());
+
+ PolicyContent updatedContent =
+ PolicyContents.columnMask("mask := action(\"replace-with-null\")");
+ PolicyEntity updated =
+ policyManager.alterPolicy(
+ METALAKE, policyName,
PolicyChange.updateContent("system_column_mask", updatedContent));
+
+ Assertions.assertEquals(updatedContent, updated.content());
+ Assertions.assertEquals(
+ updatedContent, policyManager.getPolicy(METALAKE,
policyName).content());
+
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.createPolicy(
+ METALAKE,
+ "invalid_" + policyName,
+ Policy.BuiltInType.COLUMN_MASK,
+ null,
+ true,
+ PolicyContents.columnMask("mask := action(\"unknown\")")));
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.alterPolicy(
+ METALAKE,
+ policyName,
+ PolicyChange.updateContent(
+ "system_column_mask", PolicyContents.columnMask("filter :=
true"))));
+ Assertions.assertEquals(
+ updatedContent, policyManager.getPolicy(METALAKE,
policyName).content());
Review Comment:
My feeling is that the test case is not enough. Maybe we can follow the
trino test to build a test suite out of the the code, like golden tests. So, we
can add more tests using yaml/json/txt more easily.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]