t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/CloudWatch/Alarm.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

56 lines
1.8 KiB
TypeScript

import * as AWS from "@/AWS";
import { Alarm } from "@/AWS/CloudWatch/Alarm.ts";
import * as Provider from "@/Provider";
import * as Test from "@/Test/Alchemy";
import * as cloudwatch from "@distilled.cloud/aws/cloudwatch";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
// Canonical `list()` test (AWS account/region-scoped collection): deploy a real
// CloudWatch metric alarm, resolve the provider from context via the typed
// `findProvider` helper, call `list()`, and assert the deployed alarm appears in
// the exhaustively-paginated `describeAlarms` result (filtered to MetricAlarm).
test.provider(
"list enumerates the deployed alarm",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const alarm = yield* stack.deploy(
Effect.gen(function* () {
return yield* Alarm("ListAlarm", {
MetricName: "Errors",
Namespace: "AWS/Lambda",
Statistic: "Sum",
Period: 60,
EvaluationPeriods: 1,
Threshold: 1,
ComparisonOperator: "GreaterThanOrEqualToThreshold",
});
}),
);
expect(alarm.alarmArn).toBeDefined();
const provider = yield* Provider.findProvider(Alarm);
const all = yield* provider.list();
expect(all.some((a) => a.alarmArn === alarm.alarmArn)).toBe(true);
yield* stack.destroy();
// Out-of-band assert-gone: describeAlarms by name returns an empty
// collection once the alarm is deleted.
const gone = yield* cloudwatch.describeAlarms({
AlarmNames: [alarm.alarmName],
AlarmTypes: ["MetricAlarm"],
});
expect(gone.MetricAlarms ?? []).toEqual([]);
}),
{
tags: ["provider:aws", "provider:aws:cloudwatch", "live"],
timeout: 120_000,
},
);