| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Alarm } from "@/AWS/CloudWatch/Alarm.ts"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as cloudwatch from "@distilled.cloud/aws/cloudwatch"; |
| 6 | import { expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | // Canonical `list()` test (AWS account/region-scoped collection): deploy a real |
| 12 | // CloudWatch metric alarm, resolve the provider from context via the typed |
| 13 | // `findProvider` helper, call `list()`, and assert the deployed alarm appears in |
| 14 | // the exhaustively-paginated `describeAlarms` result (filtered to MetricAlarm). |
| 15 | test.provider( |
| 16 | "list enumerates the deployed alarm", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const alarm = yield* stack.deploy( |
| 22 | Effect.gen(function* () { |
| 23 | return yield* Alarm("ListAlarm", { |
| 24 | MetricName: "Errors", |
| 25 | Namespace: "AWS/Lambda", |
| 26 | Statistic: "Sum", |
| 27 | Period: 60, |
| 28 | EvaluationPeriods: 1, |
| 29 | Threshold: 1, |
| 30 | ComparisonOperator: "GreaterThanOrEqualToThreshold", |
| 31 | }); |
| 32 | }), |
| 33 | ); |
| 34 | |
| 35 | expect(alarm.alarmArn).toBeDefined(); |
| 36 | |
| 37 | const provider = yield* Provider.findProvider(Alarm); |
| 38 | const all = yield* provider.list(); |
| 39 | |
| 40 | expect(all.some((a) => a.alarmArn === alarm.alarmArn)).toBe(true); |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | // Out-of-band assert-gone: describeAlarms by name returns an empty |
| 45 | // collection once the alarm is deleted. |
| 46 | const gone = yield* cloudwatch.describeAlarms({ |
| 47 | AlarmNames: [alarm.alarmName], |
| 48 | AlarmTypes: ["MetricAlarm"], |
| 49 | }); |
| 50 | expect(gone.MetricAlarms ?? []).toEqual([]); |
| 51 | }), |
| 52 | { |
| 53 | tags: ["provider:aws", "provider:aws:cloudwatch", "live"], |
| 54 | timeout: 120_000, |
| 55 | }, |
| 56 | ); |