1import * as AWS from "@/AWS";
2import { DBProxyEndpoint } from "@/AWS/RDS";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7
8const { test } = Test.make({ providers: AWS.providers() });
9
10// Default read-only path: resolve the provider via the typed
11// `Provider.findProvider(DBProxyEndpoint)` and call `list()` without deploying.
12// A DB proxy + endpoint needs a VPC/subnets/IAM role and takes several minutes
13// to provision (beyond the 240s budget, and the shared account hits VPC-limit /
14// no-default-VPC issues), so the deploy-backed assertion is gated below. This
15// path still exercises the full proxy enumeration + per-proxy endpoint
16// hydration code and asserts a well-typed `Attributes[]` (likely empty).
17test.provider(
18 "list returns well-typed DBProxyEndpoint attributes",
19 () =>
20 Effect.gen(function* () {
21 const provider = yield* Provider.findProvider(DBProxyEndpoint);
22 const all = yield* provider.list();
23
24 expect(Array.isArray(all)).toBe(true);
25 for (const endpoint of all) {
26 expect(typeof endpoint.dbProxyEndpointName).toBe("string");
27 expect(typeof endpoint.dbProxyEndpointArn).toBe("string");
28 expect(Array.isArray(endpoint.vpcSubnetIds)).toBe(true);
29 expect(Array.isArray(endpoint.vpcSecurityGroupIds)).toBe(true);
30 expect(typeof endpoint.tags).toBe("object");
31 }
32 }),
33 { tags: ["provider:aws", "provider:aws:rds", "live"] },
34);
35
36// Deploy-backed list test. Gated behind AWS_TEST_RDS_DBPROXY=1 because a
37// DBProxy + endpoint needs a VPC/subnets/IAM role and takes a few minutes to
38// create — beyond the 240s budget, and the shared testing account hits VPC
39// limits / no-default-VPC. Provide DBPROXY_ROLE_ARN / DBPROXY_SUBNET_IDS /
40// DBPROXY_SECRET_ARN when running on an entitled account.
41test.provider.skipIf(!process.env.AWS_TEST_RDS_DBPROXY)(
42 "list enumerates the deployed DB proxy endpoint",
43 (stack) =>
44 Effect.gen(function* () {
45 yield* stack.destroy();
46
47 const subnetIds = (process.env.DBPROXY_SUBNET_IDS ?? "").split(",");
48 const endpoint = yield* stack.deploy(
49 Effect.gen(function* () {
50 const proxy = yield* AWS.RDS.DBProxy("ListEndpointProxy", {
51 engineFamily: "POSTGRESQL",
52 roleArn: process.env.DBPROXY_ROLE_ARN!,
53 vpcSubnetIds: subnetIds,
54 auth: [
55 {
56 AuthScheme: "SECRETS",
57 SecretArn: process.env.DBPROXY_SECRET_ARN!,
58 IAMAuth: "DISABLED",
59 },
60 ],
61 });
62 return yield* DBProxyEndpoint("ListEndpoint", {
63 dbProxyName: proxy.dbProxyName,
64 vpcSubnetIds: subnetIds,
65 targetRole: "READ_ONLY",
66 });
67 }),
68 );
69
70 const provider = yield* Provider.findProvider(DBProxyEndpoint);
71 const all = yield* provider.list();
72
73 expect(
74 all.some((e) => e.dbProxyEndpointName === endpoint.dbProxyEndpointName),
75 ).toBe(true);
76
77 yield* stack.destroy();
78 }),
79 { tags: ["provider:aws", "provider:aws:rds", "live"] },
80);