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

77 lines
2.6 KiB
TypeScript

import * as AWS from "@/AWS";
import { NetworkAcl, NetworkAclAssociation, Subnet } from "@/AWS/EC2";
import * as Provider from "@/Provider";
import * as Test from "@/Test/Alchemy";
import { expect } from "alchemy-test";
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import { MinimumLogLevel } from "effect/References";
import * as Schedule from "effect/Schedule";
import { getDefaultVpc } from "../DefaultVpc.ts";
import { assertNetworkAclGone, assertSubnetGone } from "./Gone.ts";
const { test } = Test.make({ providers: AWS.providers() });
const logLevel = Effect.provideService(
MinimumLogLevel,
process.env.DEBUG ? "Debug" : "Info",
);
class NetworkAclAssociationNotListed extends Data.TaggedError(
"NetworkAclAssociationNotListed",
)<{}> {}
test.provider(
"list enumerates the deployed NetworkAclAssociation",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const defaultVpc = yield* getDefaultVpc;
const { subnet, acl, assoc } = yield* stack.deploy(
Effect.gen(function* () {
const subnet = yield* Subnet("ListNaclAssocSubnet", {
vpcId: defaultVpc.vpcId,
cidrBlock: defaultVpc.subnetCidrBlock(221),
});
const acl = yield* NetworkAcl("ListNaclAssocAcl", {
vpcId: defaultVpc.vpcId,
});
const assoc = yield* NetworkAclAssociation("ListNaclAssoc", {
networkAclId: acl.networkAclId,
subnetId: subnet.subnetId,
});
return { subnet, acl, assoc };
}),
);
const provider = yield* Provider.findProvider(NetworkAclAssociation);
const all = yield* provider.list().pipe(
Effect.flatMap((all) =>
all.some((x) => x.associationId === assoc.associationId)
? Effect.succeed(all)
: Effect.fail(new NetworkAclAssociationNotListed()),
),
Effect.retry({
while: (e) => e._tag === "NetworkAclAssociationNotListed",
schedule: Schedule.max([
Schedule.spaced("3 seconds"),
Schedule.recurs(10),
]),
}),
);
expect(all.some((x) => x.associationId === assoc.associationId)).toBe(
true,
);
yield* stack.destroy();
// The default VPC is shared/standing — assert the resources this test
// created inside it (subnet + ACL, whose deletion also proves the
// association was released) are gone.
yield* assertNetworkAclGone(acl.networkAclId);
yield* assertSubnetGone(subnet.subnetId);
}).pipe(logLevel),
{ tags: ["provider:aws", "provider:aws:ec2", "live"] },
);