1import * as AWS from "@/AWS";
2import { InternetGateway, Route, RouteTable, 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 { assertRouteTableGone, 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 Route",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22
23 const deployed = yield* stack.deploy(
24 Effect.gen(function* () {
25 const vpc = yield* Vpc("ListRouteVpc", {
26 cidrBlock: "10.0.0.0/16",
27 });
28 const igw = yield* InternetGateway("ListRouteIgw", {
29 vpcId: vpc.vpcId,
30 });
31 const routeTable = yield* RouteTable("ListRouteTable", {
32 vpcId: vpc.vpcId,
33 });
34 const route = yield* Route("ListRoute", {
35 routeTableId: routeTable.routeTableId,
36 destinationCidrBlock: "0.0.0.0/0",
37 gatewayId: igw.internetGatewayId,
38 });
39 return { vpc, routeTable, route };
40 }),
41 );
42
43 const provider = yield* Provider.findProvider(Route);
44 const all = yield* provider.list();
45
46 expect(
47 all.some(
48 (x) =>
49 x.routeTableId === deployed.route.routeTableId &&
50 x.destinationCidrBlock === deployed.route.destinationCidrBlock &&
51 x.gatewayId === deployed.route.gatewayId,
52 ),
53 ).toBe(true);
54
55 yield* stack.destroy();
56
57 // A route has no standalone id — its route table (and the whole VPC)
58 // being gone proves the route was torn down.
59 yield* assertRouteTableGone(deployed.routeTable.routeTableId);
60 yield* assertVpcGone(deployed.vpc.vpcId);
61 }).pipe(logLevel),
62 { tags: ["provider:aws", "provider:aws:ec2", "live"] },
63);