mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(common): share map value constraint messages (#9242)
Adds Violations.mapValues beside mapKeys and builds the map value constraint messages of AgentCore, SES v2, Firehose and Lambda with it. The Bedrock tag rules drop the unreachable null branch, and AgentCore keeps its null-key error at its own boundary. The messages are unchanged. Closes #9241
This commit is contained in:
1 parent
806b822576
commit
bf68a01fc2
8 files changed
+68
-26
No files matched your search
@@ -122,4 +122,26 @@ class SmithyValidationErrorsTest {
|
||||
assertNull(without.lengthOutOfRange("userName", "abc", 3, 10));
|
||||
assertNull(without.outOfRange("maxItems", 1000, 1, 1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapValuesPreserveEachServicesValueFormAndRuleOrder() {
|
||||
List<String> rules = List.of("Member must have length less than or equal to 3",
|
||||
"Member must have length greater than or equal to 0",
|
||||
"Member must satisfy regular expression pattern: [a-z]*");
|
||||
String suffix = "Map value must satisfy constraint: [Member must have length less than or equal to 3, "
|
||||
+ "Member must have length greater than or equal to 0, "
|
||||
+ "Member must satisfy regular expression pattern: [a-z]*]";
|
||||
assertEquals("Value '{key=BAD}' at 'tags' failed to satisfy constraint: " + suffix,
|
||||
SmithyValidationErrors.Violations.QUOTED.mapValues("tags", "{key=BAD}", rules));
|
||||
assertEquals("Value at 'tags' failed to satisfy constraint: " + suffix,
|
||||
SmithyValidationErrors.Violations.WITHOUT_VALUES.mapValues("tags", "secret", rules));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapValuesRetainAnEmptyRuleSetAndNullQuotedValue() {
|
||||
assertEquals("Value 'null' at 'filter' failed to satisfy constraint: Map value must satisfy constraint: []",
|
||||
SmithyValidationErrors.Violations.QUOTED.mapValues("filter", null, List.of()));
|
||||
assertEquals("Value at 'filter' failed to satisfy constraint: Map value must satisfy constraint: []",
|
||||
SmithyValidationErrors.Violations.WITHOUT_VALUES.mapValues("filter", null, List.of()));
|
||||
}
|
||||
}
|
||||
+26
@@ -73,6 +73,32 @@ class BedrockAgentCoreTagValidationTest {
|
||||
assertDoesNotThrow(() -> BedrockAgentCoreTagValidation.validateTags(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void directMapNullMembersKeepTheirErrors() {
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
tags.put(null, "value");
|
||||
AwsException keyError = assertThrows(AwsException.class,
|
||||
() -> BedrockAgentCoreTagValidation.validateTagMap(tags));
|
||||
assertEquals("ValidationException", keyError.getErrorCode());
|
||||
assertEquals(400, keyError.getHttpStatus());
|
||||
assertEquals("1 validation error detected: Value null at 'tags.key' failed to satisfy constraint: "
|
||||
+ "Member must not be null", keyError.getMessage());
|
||||
|
||||
tags.clear();
|
||||
tags.put("key", null);
|
||||
AwsException valueError = assertThrows(AwsException.class,
|
||||
() -> BedrockAgentCoreTagValidation.validateTagMap(tags));
|
||||
assertEquals("ValidationException", valueError.getErrorCode());
|
||||
assertEquals(400, valueError.getHttpStatus());
|
||||
assertEquals("tag value must be a string", valueError.getMessage());
|
||||
|
||||
AwsException mapError = assertThrows(AwsException.class,
|
||||
() -> BedrockAgentCoreTagValidation.validateTagMap(null));
|
||||
assertEquals("ValidationException", mapError.getErrorCode());
|
||||
assertEquals(400, mapError.getHttpStatus());
|
||||
assertEquals("tags must be an object with at most 50 entries", mapError.getMessage());
|
||||
}
|
||||
|
||||
private static Stream<Arguments> modeledTagFailures() {
|
||||
String prefix = "1 validation error detected: ";
|
||||
String keyRules = "Value at 'tags' failed to satisfy constraint: Map keys must satisfy constraint: ["
|
||||
|
||||
Reference in new issue
Block a user