mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(redshift): share one Tags writer across the query builders (#8086)
RedshiftQueryHandler wrote the same Tags/Tag loop in eight resource builders: clusters, snapshots, cluster parameter groups, cluster subnet groups, snapshot schedules, event subscriptions, snapshot copy grants and integrations. They now call one tagsXml helper. The XML is unchanged. Clusters, snapshot copy grants and integrations still leave out an empty Tags list, and the other five still write one. A new RedshiftQueryHandlerTest case pins both shapes for all eight; it passes before and after the change.
This commit is contained in:
1 parent
410e09bf62
commit
8bdf86420b
2 files changed
+78
-56
No files matched your search
@@ -11,6 +11,7 @@ import io.floci.aws.services.redshift.model.ClusterParameterGroup;
|
||||
import io.floci.aws.services.redshift.model.ClusterSubnetGroup;
|
||||
import io.floci.aws.services.redshift.model.Endpoint;
|
||||
import io.floci.aws.services.redshift.model.EventSubscription;
|
||||
import io.floci.aws.services.redshift.model.Integration;
|
||||
import io.floci.aws.services.redshift.model.Parameter;
|
||||
import io.floci.aws.services.redshift.model.Snapshot;
|
||||
import io.floci.aws.services.redshift.model.SnapshotCopyGrant;
|
||||
@@ -23,6 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1309,6 +1311,62 @@ class RedshiftQueryHandlerTest {
|
||||
assertTrue(xml.contains("<Value>prod</Value>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeResponsesListTagsAndClustersGrantsAndIntegrationsOmitAnEmptyList() {
|
||||
List<String> describes = List.of("DescribeClusters", "DescribeClusterSnapshots",
|
||||
"DescribeClusterParameterGroups", "DescribeClusterSubnetGroups", "DescribeSnapshotSchedules",
|
||||
"DescribeEventSubscriptions", "DescribeSnapshotCopyGrants", "DescribeIntegrations");
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
tags.put("team", "red");
|
||||
tags.put("env", "dev");
|
||||
stubOneOfEachTaggedResource(tags);
|
||||
for (String action : describes) {
|
||||
String xml = (String) handler.handle(action, new MultivaluedHashMap<>()).getEntity();
|
||||
assertTrue(xml.contains("<Tags><Tag><Key>team</Key><Value>red</Value></Tag>"
|
||||
+ "<Tag><Key>env</Key><Value>dev</Value></Tag></Tags>"), action);
|
||||
}
|
||||
|
||||
List<String> omitEmpty = List.of("DescribeClusters", "DescribeSnapshotCopyGrants", "DescribeIntegrations");
|
||||
stubOneOfEachTaggedResource(Map.of());
|
||||
for (String action : describes) {
|
||||
String xml = (String) handler.handle(action, new MultivaluedHashMap<>()).getEntity();
|
||||
assertEquals(!omitEmpty.contains(action), xml.contains("<Tags></Tags>"), action);
|
||||
assertEquals(!omitEmpty.contains(action), xml.contains("<Tags>"), action);
|
||||
}
|
||||
}
|
||||
|
||||
private void stubOneOfEachTaggedResource(Map<String, String> tags) {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setTags(tags);
|
||||
when(service.describeClusters(any())).thenReturn(List.of(cluster));
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setTags(tags);
|
||||
when(service.describeSnapshots(any(), any())).thenReturn(List.of(snapshot));
|
||||
ClusterParameterGroup parameterGroup = new ClusterParameterGroup();
|
||||
parameterGroup.setTags(tags);
|
||||
when(service.describeClusterParameterGroups(any())).thenReturn(List.of(parameterGroup));
|
||||
ClusterSubnetGroup subnetGroup = new ClusterSubnetGroup();
|
||||
subnetGroup.setTags(tags);
|
||||
when(service.describeClusterSubnetGroups(any())).thenReturn(List.of(subnetGroup));
|
||||
SnapshotSchedule schedule = new SnapshotSchedule();
|
||||
schedule.setTags(tags);
|
||||
when(service.describeSnapshotSchedules(any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(new PaginatedResult<>(List.of(schedule), null));
|
||||
EventSubscription subscription = new EventSubscription();
|
||||
subscription.setSubscriptionCreationTime(Instant.parse("2026-11-12T00:00:00Z"));
|
||||
subscription.setTags(tags);
|
||||
when(service.describeEventSubscriptions(any(), any(), any(), any(), any()))
|
||||
.thenReturn(new PaginatedResult<>(List.of(subscription), null));
|
||||
SnapshotCopyGrant grant = new SnapshotCopyGrant();
|
||||
grant.setTags(tags);
|
||||
when(service.describeSnapshotCopyGrants(any(), any(), any()))
|
||||
.thenReturn(new PaginatedResult<>(List.of(grant), null));
|
||||
Integration integration = new Integration();
|
||||
integration.setTags(tags);
|
||||
when(service.describeIntegrations(any(), any(), any(), any()))
|
||||
.thenReturn(new RedshiftService.IntegrationPage(List.of(integration), null));
|
||||
}
|
||||
|
||||
// ── GetClusterCredentials ────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user