test(cloudwatch): share alarm cleanup requests (#8430)

This commit is contained in:
Jackson Price authored and GitHub committed 2026-11-15 08:18:54 -04:00
1 parent 0ae7f8bf89
commit 70924d4afc
4 files changed
+12 -23

No files matched your search

@@ -111,14 +111,7 @@ class CloudWatchAlarmHistoryIntegrationTest {
private Response call(boolean json, String operation, Map<String, ?> 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);
}
@@ -245,13 +245,7 @@ class CloudWatchDescribeAlarmsFiltersIntegrationTest {
private void put(boolean json, String operation, Map<String, Object> 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 {
@@ -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<String, ?> body)
throws JsonProcessingException {
if (json) {
@@ -285,14 +285,7 @@ class CompositeAlarmIntegrationTest {
private Response call(boolean json, String operation, Map<String, ?> 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);
}