Copilot commented on code in PR #12686:
URL: https://github.com/apache/gravitino/pull/12686#discussion_r3906426635
##########
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:
##########
@@ -354,6 +354,61 @@ public void testAlterPolicy() {
Assertions.assertTrue(enabledPolicy.enabled());
}
+ @Test
+ public void testAlterBuiltInPolicyContent() {
+ String policyName = "policy_" + UUID.randomUUID().toString().replace("-",
"");
+ policyManager.createPolicy(
+ METALAKE,
+ policyName,
+ Policy.BuiltInType.ICEBERG_COMPACTION,
+ null,
+ true,
+ PolicyContents.icebergDataCompaction());
+
+ // Adding a type not in the original set must be rejected.
+ Set<MetadataObject.Type> withExtra =
+ ImmutableSet.of(
+ MetadataObject.Type.CATALOG,
+ MetadataObject.Type.SCHEMA,
+ MetadataObject.Type.TABLE,
+ MetadataObject.Type.FILESET);
+ PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(),
withExtra, null);
+ IllegalArgumentException addEx =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.alterPolicy(
+ METALAKE,
+ policyName,
+ PolicyChange.updateContent("system_iceberg_compaction",
addedType)));
+ Assertions.assertTrue(
+ addEx.getMessage().contains("Policy content type mismatch"),
+ "expected mismatch message, got: " + addEx.getMessage());
+ // Format arguments must be substituted — neither placeholder should
survive literally.
+ Assertions.assertFalse(
+ addEx.getMessage().contains("%s"),
+ "format args were not substituted: " + addEx.getMessage());
Review Comment:
The test currently only checks that "%s" placeholders are gone; it doesn't
verify the updated message actually includes the expected/actual
supportedObjectTypes sets (which is part of this PR's behavior change).
Asserting both set values appear will prevent regressions that still remove
"%s" but omit the sets.
This issue also appears on line 407 of the same file.
##########
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:
##########
@@ -354,6 +354,61 @@ public void testAlterPolicy() {
Assertions.assertTrue(enabledPolicy.enabled());
}
+ @Test
+ public void testAlterBuiltInPolicyContent() {
+ String policyName = "policy_" + UUID.randomUUID().toString().replace("-",
"");
+ policyManager.createPolicy(
+ METALAKE,
+ policyName,
+ Policy.BuiltInType.ICEBERG_COMPACTION,
+ null,
+ true,
+ PolicyContents.icebergDataCompaction());
+
+ // Adding a type not in the original set must be rejected.
+ Set<MetadataObject.Type> withExtra =
+ ImmutableSet.of(
+ MetadataObject.Type.CATALOG,
+ MetadataObject.Type.SCHEMA,
+ MetadataObject.Type.TABLE,
+ MetadataObject.Type.FILESET);
+ PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(),
withExtra, null);
+ IllegalArgumentException addEx =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ policyManager.alterPolicy(
+ METALAKE,
+ policyName,
+ PolicyChange.updateContent("system_iceberg_compaction",
addedType)));
Review Comment:
Avoid hard-coding the built-in policy type string here; using the enum
constant keeps the test aligned if the policy type value ever changes.
This issue also appears on line 403 of the same file.
--
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]