1import * as AWS from "@/AWS";
2import * as Provider from "@/Provider";
3import * as Test from "./Test.ts";
4import * as ag from "@distilled.cloud/aws/api-gateway";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { assertVpcLinkDeleted } from "./assertions.ts";
8
9const { test } = Test.make({ providers: AWS.providers() });
10
11const targetArn = process.env.ALCHEMY_TEST_VPC_LINK_TARGET_ARN;
12
13/**
14 * Requires a load balancer ARN accepted by API Gateway VPC links (set env when running live).
15 */
16test.provider.skipIf(!!process.env.FAST || !targetArn)(
17 "create, update description, delete VPC link",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const arn = targetArn!;
23
24 const link = yield* stack.deploy(
25 Effect.gen(function* () {
26 return yield* AWS.ApiGateway.VpcLink("AgVpcLinkTest", {
27 description: "v1",
28 targetArns: [arn],
29 });
30 }),
31 );
32
33 expect(link.vpcLinkId).toBeDefined();
34
35 yield* stack.deploy(
36 Effect.gen(function* () {
37 return yield* AWS.ApiGateway.VpcLink("AgVpcLinkTest", {
38 description: "v2",
39 targetArns: [arn],
40 });
41 }),
42 );
43
44 const remote = yield* ag.getVpcLink({ vpcLinkId: link.vpcLinkId });
45 expect(remote.description).toEqual("v2");
46
47 yield* stack.destroy();
48 yield* assertVpcLinkDeleted(link.vpcLinkId);
49 }),
50 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
51);
52
53/**
54 * A VPC link requires an NLB target ARN, which is heavy to provision in CI,
55 * so this is gated behind the same env vars as the lifecycle test above.
56 */
57test.provider.skipIf(!!process.env.FAST || !targetArn)(
58 "list enumerates the deployed VPC link",
59 (stack) =>
60 Effect.gen(function* () {
61 const arn = targetArn!;
62
63 yield* stack.destroy();
64
65 const link = yield* stack.deploy(
66 Effect.gen(function* () {
67 return yield* AWS.ApiGateway.VpcLink("AgVpcLinkList", {
68 description: "list",
69 targetArns: [arn],
70 });
71 }),
72 );
73
74 const provider = yield* Provider.findProvider(AWS.ApiGateway.VpcLink);
75 const all = yield* provider.list();
76
77 expect(all.some((v) => v.vpcLinkId === link.vpcLinkId)).toBe(true);
78
79 yield* stack.destroy();
80 yield* assertVpcLinkDeleted(link.vpcLinkId);
81 }),
82 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
83);