| 1 | import * as AWS from "@/AWS"; |
| 2 | import { EgressOnlyInternetGateway, Vpc } from "@/AWS/EC2"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "./VpcTest.ts"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import { assertVpcGone } from "./Gone.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | test.provider( |
| 18 | "list enumerates the deployed Egress-Only Internet Gateway", |
| 19 | (stack) => |
| 20 | Effect.gen(function* () { |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const { vpc, eigw } = yield* stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | const vpc = yield* Vpc("ListEigwVpc", { |
| 26 | cidrBlock: "10.0.0.0/16", |
| 27 | }); |
| 28 | const eigw = yield* EgressOnlyInternetGateway("ListEigw", { |
| 29 | vpcId: vpc.vpcId, |
| 30 | }); |
| 31 | return { vpc, eigw }; |
| 32 | }), |
| 33 | ); |
| 34 | |
| 35 | const provider = yield* Provider.findProvider(EgressOnlyInternetGateway); |
| 36 | const all = yield* provider.list(); |
| 37 | |
| 38 | expect( |
| 39 | all.some( |
| 40 | (x) => |
| 41 | x.egressOnlyInternetGatewayId === eigw.egressOnlyInternetGatewayId, |
| 42 | ), |
| 43 | ).toBe(true); |
| 44 | |
| 45 | yield* stack.destroy(); |
| 46 | |
| 47 | // The VPC cannot delete while the egress-only IGW exists, so VPC-gone |
| 48 | // proves the whole stack (EIGW included) was torn down. |
| 49 | yield* assertVpcGone(vpc.vpcId); |
| 50 | }).pipe(logLevel), |
| 51 | { tags: ["provider:aws", "provider:aws:ec2", "live"] }, |
| 52 | ); |