| 1 | import { AnomalyDetector } from "@/AWS/CloudWatch"; |
| 2 | import * as AWS from "@/AWS"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | // `list()` enumerates every CloudWatch anomaly detector in the account/region |
| 11 | // via the paginated `cloudwatch.describeAnomalyDetectors` op. Deploy a real |
| 12 | // single-metric detector, resolve the provider from context via the typed |
| 13 | // `findProvider`, call `list()`, and assert the deployed detector appears in the |
| 14 | // exhaustively paginated result (matched by its stable `detectorId` identity). |
| 15 | test.provider( |
| 16 | "list enumerates the deployed anomaly detector", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const detector = yield* stack.deploy( |
| 22 | Effect.gen(function* () { |
| 23 | return yield* AnomalyDetector("ListAnomalyDetector", { |
| 24 | Namespace: "AWS/Lambda", |
| 25 | MetricName: "Errors", |
| 26 | Stat: "Sum", |
| 27 | Dimensions: [ |
| 28 | { Name: "FunctionName", Value: "alchemy-test-anomaly-list" }, |
| 29 | ], |
| 30 | }); |
| 31 | }), |
| 32 | ); |
| 33 | |
| 34 | const provider = yield* Provider.findProvider(AnomalyDetector); |
| 35 | const all = yield* provider.list(); |
| 36 | |
| 37 | expect(all.some((d) => d.detectorId === detector.detectorId)).toBe(true); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | |
| 41 | // Out-of-band assert-gone: the exhaustively-paginated live listing no |
| 42 | // longer contains the detector after the final destroy. |
| 43 | const after = yield* provider.list(); |
| 44 | expect(after.some((d) => d.detectorId === detector.detectorId)).toBe( |
| 45 | false, |
| 46 | ); |
| 47 | }), |
| 48 | { |
| 49 | tags: ["provider:aws", "provider:aws:cloudwatch", "live"], |
| 50 | timeout: 240_000, |
| 51 | }, |
| 52 | ); |