From 70924d4afc88d58d8439ba8f405448703cf1490e Mon Sep 17 00:00:00 2001 From: Jackson Price <59149601+jprice8@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:18:54 -0600 Subject: [PATCH] test(cloudwatch): share alarm cleanup requests (#8430) --- .../metrics/CloudWatchAlarmHistoryIntegrationTest.java | 9 +-------- .../CloudWatchDescribeAlarmsFiltersIntegrationTest.java | 8 +------- .../cloudwatch/metrics/CloudWatchTestRequests.java | 9 +++++++++ .../metrics/CompositeAlarmIntegrationTest.java | 9 +-------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchAlarmHistoryIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchAlarmHistoryIntegrationTest.java index 8715521c89..5a1591d16d 100644 --- a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchAlarmHistoryIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchAlarmHistoryIntegrationTest.java @@ -111,14 +111,7 @@ class CloudWatchAlarmHistoryIntegrationTest { private Response call(boolean json, String operation, Map body) throws JsonProcessingException { if ("PutMetricAlarm".equals(operation)) { String name = body.get("AlarmName").toString(); - cleanup.register(() -> { - try { - CloudWatchTestRequests.call(baseUri, SCOPE, true, "DeleteAlarms", - Map.of("AlarmNames", List.of(name))).then().statusCode(200); - } catch (JsonProcessingException e) { - throw new IllegalStateException(e); - } - }); + cleanup.register(() -> CloudWatchTestRequests.deleteAlarmJson(baseUri, SCOPE, name)); } return CloudWatchTestRequests.call(baseUri, SCOPE, json, operation, body); } diff --git a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchDescribeAlarmsFiltersIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchDescribeAlarmsFiltersIntegrationTest.java index 769e9052c5..1fd64bc203 100644 --- a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchDescribeAlarmsFiltersIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchDescribeAlarmsFiltersIntegrationTest.java @@ -245,13 +245,7 @@ class CloudWatchDescribeAlarmsFiltersIntegrationTest { private void put(boolean json, String operation, Map request) throws Exception { call(json, operation, request).then().statusCode(200); String name = request.get("AlarmName").toString(); - cleanup.register(() -> { - try { - call(true, "DeleteAlarms", Map.of("AlarmNames", List.of(name))).then().statusCode(200); - } catch (JsonProcessingException e) { - throw new IllegalStateException(e); - } - }); + cleanup.register(() -> CloudWatchTestRequests.deleteAlarmJson(baseUri, SCOPE, name)); } private void setState(boolean json, String name, String state) throws Exception { diff --git a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchTestRequests.java b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchTestRequests.java index 64f080a36b..a2e629610d 100644 --- a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchTestRequests.java +++ b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CloudWatchTestRequests.java @@ -18,6 +18,15 @@ final class CloudWatchTestRequests { private CloudWatchTestRequests() { } + static void deleteAlarmJson(URI endpoint, String scope, String name) { + try { + call(endpoint, scope, true, "DeleteAlarms", Map.of("AlarmNames", List.of(name))) + .then().statusCode(200); + } catch (JsonProcessingException e) { + throw new IllegalStateException(e); + } + } + static Response call(URI endpoint, String scope, boolean json, String operation, Map body) throws JsonProcessingException { if (json) { diff --git a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CompositeAlarmIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CompositeAlarmIntegrationTest.java index b9b8c260b8..487257d3f5 100644 --- a/src/test/java/io/floci/aws/services/cloudwatch/metrics/CompositeAlarmIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudwatch/metrics/CompositeAlarmIntegrationTest.java @@ -285,14 +285,7 @@ class CompositeAlarmIntegrationTest { private Response call(boolean json, String operation, Map body) throws JsonProcessingException { if ("PutCompositeAlarm".equals(operation) || "PutMetricAlarm".equals(operation)) { String name = body.get("AlarmName").toString(); - cleanup.register(() -> { - try { - CloudWatchTestRequests.call(baseUri, SCOPE, true, "DeleteAlarms", - Map.of("AlarmNames", List.of(name))).then().statusCode(200); - } catch (JsonProcessingException e) { - throw new IllegalStateException(e); - } - }); + cleanup.register(() -> CloudWatchTestRequests.deleteAlarmJson(baseUri, SCOPE, name)); } return CloudWatchTestRequests.call(baseUri, SCOPE, json, operation, body); }