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