1import * as AWS from "@/AWS";
2import { RouteTable, RouteTableAssociation, Subnet, Vpc } from "@/AWS/EC2";
3import * as Provider from "@/Provider";
4import * as Test from "./VpcTest.ts";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { MinimumLogLevel } from "effect/References";
8import { assertVpcGone } from "./Gone.ts";
9
10const { test } = Test.make({ providers: AWS.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17test.provider(
18 "list enumerates the deployed RouteTableAssociation",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22
23 const { vpc, assoc } = yield* stack.deploy(
24 Effect.gen(function* () {
25 const vpc = yield* Vpc("ListRtbAssocVpc", {
26 cidrBlock: "10.0.0.0/16",
27 });
28 const subnet = yield* Subnet("ListRtbAssocSubnet", {
29 vpcId: vpc.vpcId,
30 cidrBlock: "10.0.1.0/24",
31 });
32 const routeTable = yield* RouteTable("ListRtbAssocRt", {
33 vpcId: vpc.vpcId,
34 });
35 const assoc = yield* RouteTableAssociation("ListRtbAssoc", {
36 routeTableId: routeTable.routeTableId,
37 subnetId: subnet.subnetId,
38 });
39 return { vpc, subnet, routeTable, assoc };
40 }),
41 );
42
43 const provider = yield* Provider.findProvider(RouteTableAssociation);
44 const all = yield* provider.list();
45
46 expect(all.some((x) => x.associationId === assoc.associationId)).toBe(
47 true,
48 );
49
50 yield* stack.destroy();
51
52 // The VPC cannot delete while the subnet/route-table/association exist —
53 // VPC-gone proves full teardown.
54 yield* assertVpcGone(vpc.vpcId);
55 }).pipe(logLevel),
56 { tags: ["provider:aws", "provider:aws:ec2", "live"] },
57);