1import * as AWS from "@/AWS";
2import { DBProxy } 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(DBProxy)` and call `list()` without deploying. A
12// DB proxy requires a VPC/subnets/IAM role and takes several minutes to
13// provision (beyond the 240s budget, and the shared account has VPC-limit /
14// no-default-VPC issues), so the deploy-backed assertion is gated below. This
15// path still exercises the full enumeration + tag-hydration code and asserts a
16// well-typed `Attributes[]`.
17test.provider(
18 "list returns well-typed DBProxy attributes",
19 () =>
20 Effect.gen(function* () {
21 const provider = yield* Provider.findProvider(DBProxy);
22 const all = yield* provider.list();
23
24 expect(Array.isArray(all)).toBe(true);
25 for (const proxy of all) {
26 expect(typeof proxy.dbProxyName).toBe("string");
27 expect(typeof proxy.dbProxyArn).toBe("string");
28 expect(Array.isArray(proxy.vpcSubnetIds)).toBe(true);
29 expect(Array.isArray(proxy.vpcSecurityGroupIds)).toBe(true);
30 expect(typeof proxy.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 needs a VPC/subnets/IAM role and takes a few minutes to create —
38// beyond the 240s budget, and the shared testing account hits VPC limits /
39// 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",
43 (stack) =>
44 Effect.gen(function* () {
45 yield* stack.destroy();
46
47 const subnetIds = (process.env.DBPROXY_SUBNET_IDS ?? "").split(",");
48 const proxy = yield* stack.deploy(
49 Effect.gen(function* () {
50 return yield* DBProxy("ListDBProxy", {
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 }),
63 );
64
65 const provider = yield* Provider.findProvider(DBProxy);
66 const all = yield* provider.list();
67
68 expect(all.some((p) => p.dbProxyName === proxy.dbProxyName)).toBe(true);
69
70 yield* stack.destroy();
71 }),
72 { tags: ["provider:aws", "provider:aws:rds", "live"] },
73);