mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(core): move the Query list member pattern into a shared helper (#6306)
PassedRoles, in core.common, read a Redshift cluster's roles through RedshiftQueryHandler.memberKeyRegex, so core depended on a service class. The pattern now lives in core.common.AwsQueryLists, and both call it. AwsQueryLists reads a list's numbered members in the three forms the Redshift and RDS handlers accepted: the generic List.member.N, List.Name.N when the list's shape names its member, and a bare List.N, every N in numeric order with no stop at a gap. memberKeys gives the key pattern, values the non-blank values, and memberIndex the number a key ends in, which the Redshift handler also sorts its integration filters and parameters by. The Redshift and RDS handlers each keep their table of the names their list shapes give their members (Redshift's SubnetIdentifier and IamRoleArn, RDS's OptionName and AttributeValue, and so on) and pass the name in, so the helper holds nothing specific to either. RDS had its own copy of the reader, memberKeyRegex and numericSuffix included, and now calls the helper too. PassedRoles names IamRoleArn for IamRoles and AddIamRoles, the way its other cases name the members the handlers read. No behaviour changes: the same keys are matched, in the same order, and the same values read.
This commit is contained in:
1 parent
dace33ddcc
commit
27caa82349
5 files changed
+148
-66
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class AwsQueryListsTest {
|
||||
|
||||
@Test
|
||||
void aMemberKeyIsGenericNamedByItsShapeOrBare() {
|
||||
Pattern keys = AwsQueryLists.memberKeys("IamRoles", "IamRoleArn");
|
||||
|
||||
assertTrue(keys.matcher("IamRoles.member.1").matches());
|
||||
assertTrue(keys.matcher("IamRoles.IamRoleArn.2").matches());
|
||||
assertTrue(keys.matcher("IamRoles.10").matches());
|
||||
assertFalse(keys.matcher("IamRoles.Other.1").matches());
|
||||
assertFalse(keys.matcher("AddIamRoles.member.1").matches());
|
||||
assertFalse(keys.matcher("IamRolesExtra.1").matches());
|
||||
assertFalse(keys.matcher("IamRoles.member.1.Arn").matches());
|
||||
assertFalse(keys.matcher("IamRoles").matches());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aListWhoseShapeNamesNoMemberTakesOnlyTheGenericForm() {
|
||||
Pattern keys = AwsQueryLists.memberKeys("LogExports", null);
|
||||
|
||||
assertTrue(keys.matcher("LogExports.member.1").matches());
|
||||
assertTrue(keys.matcher("LogExports.1").matches());
|
||||
assertFalse(keys.matcher("LogExports.LogExport.1").matches());
|
||||
}
|
||||
|
||||
@Test
|
||||
void valuesAreEveryNonBlankMemberInNumericOrderPastAGap() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("SubnetIds.SubnetIdentifier.10", "tenth");
|
||||
params.putSingle("SubnetIds.member.2", "second");
|
||||
params.putSingle("SubnetIds.5", " ");
|
||||
params.putSingle("SubnetIds.1", "first");
|
||||
params.putSingle("VpcSecurityGroupIds.member.3", "other list");
|
||||
|
||||
assertEquals(List.of("first", "second", "tenth"),
|
||||
AwsQueryLists.values(params, "SubnetIds", "SubnetIdentifier"));
|
||||
assertEquals(List.of(), AwsQueryLists.values(params, "TagKeys", "TagKey"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMemberIndexIsTheNumberTheKeyEndsIn() {
|
||||
assertEquals(12, AwsQueryLists.memberIndex("Filters.Filter.3.Values.Value.12"));
|
||||
assertEquals(Integer.MAX_VALUE, AwsQueryLists.memberIndex("Name"));
|
||||
assertEquals(Integer.MAX_VALUE, AwsQueryLists.memberIndex("List.member."));
|
||||
assertEquals(Integer.MAX_VALUE, AwsQueryLists.memberIndex("List.member.99999999999"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user