t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/AutoScaling/LaunchTemplate.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

70 lines
2.4 KiB
TypeScript

import * as AWS from "@/AWS";
import { LaunchTemplate } from "@/AWS/AutoScaling";
import { amazonLinux2023 } from "@/AWS/EC2";
import * as Provider from "@/Provider";
import * as Test from "@/Test/Alchemy";
import * as ec2 from "@distilled.cloud/aws/ec2";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
// `list()` enumerates every launch template in the account/region via the
// paginated `ec2.describeLaunchTemplates` op. Deploy a real launch template,
// resolve the provider from context via the typed `findProvider`, call
// `list()`, and assert the deployed template appears in the exhaustively
// paginated result. (The greenfield read path depends on the distilled `ec2`
// patch that types `InvalidLaunchTemplateName.NotFoundException` on
// `describeLaunchTemplates` — landed in patches/ec2.json.)
test.provider(
"list enumerates the deployed launch template",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
// Launch templates do not validate the AMI at creation time; fall back to a
// syntactically valid id if the lookup returns nothing.
const imageId = amazonLinux2023();
const template = yield* stack.deploy(
Effect.gen(function* () {
return yield* LaunchTemplate("ListLaunchTemplate", {
launchTemplateName: "alchemy-test-lt-list",
imageId,
instanceType: "t3.micro",
});
}),
);
const provider = yield* Provider.findProvider(LaunchTemplate);
const all = yield* provider.list();
expect(
all.some((t) => t.launchTemplateId === template.launchTemplateId),
).toBe(true);
yield* stack.destroy();
// Out-of-band proof the template is gone: describing the deleted name
// raises the typed `InvalidLaunchTemplateName.NotFoundException`.
const remaining = yield* ec2
.describeLaunchTemplates({
LaunchTemplateNames: ["alchemy-test-lt-list"],
} as any)
.pipe(
Effect.map((r) => (r.LaunchTemplates ?? []).length),
Effect.catchTag("InvalidLaunchTemplateName.NotFoundException", () =>
Effect.succeed(0),
),
);
expect(remaining).toBe(0);
}),
{
tags: [
"provider:aws",
"provider:aws:autoscaling",
"provider:aws:ec2",
"live",
],
},
);