| 1 | import * as AWS from "@/AWS"; |
| 2 | import { DBClusterEndpoint } 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 | // Read-only `list()` path (default): resolve the provider from context via the |
| 11 | // typed `Provider.findProvider`, call `list()`, and assert a well-typed |
| 12 | // `Attributes[]` is returned. No deploy — spinning up an Aurora cluster + custom |
| 13 | // endpoint takes many minutes, far beyond the 240s budget. The account likely |
| 14 | // has zero custom cluster endpoints, so the array is typically empty; we only |
| 15 | // assert shape correctness here. |
| 16 | test.provider( |
| 17 | "list returns typed custom cluster endpoints", |
| 18 | () => |
| 19 | Effect.gen(function* () { |
| 20 | const provider = yield* Provider.findProvider(DBClusterEndpoint); |
| 21 | const all = yield* provider.list(); |
| 22 | |
| 23 | expect(Array.isArray(all)).toBe(true); |
| 24 | for (const endpoint of all) { |
| 25 | expect(typeof endpoint.dbClusterEndpointIdentifier).toBe("string"); |
| 26 | expect(Array.isArray(endpoint.staticMembers)).toBe(true); |
| 27 | expect(Array.isArray(endpoint.excludedMembers)).toBe(true); |
| 28 | expect(typeof endpoint.tags).toBe("object"); |
| 29 | } |
| 30 | }), |
| 31 | { tags: ["provider:aws", "provider:aws:rds", "live"] }, |
| 32 | ); |
| 33 | |
| 34 | // Full deploy-based `list()` verification, gated behind an env var because |
| 35 | // provisioning an Aurora DB cluster and a custom endpoint takes many minutes. |
| 36 | // Run with AWS_TEST_RDS_DBCLUSTER_ENDPOINT=1 on an account willing to pay the |
| 37 | // provisioning cost. |
| 38 | test.provider.skipIf(!process.env.AWS_TEST_RDS_DBCLUSTER_ENDPOINT)( |
| 39 | "list enumerates the deployed custom cluster endpoint", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const endpoint = yield* stack.deploy( |
| 45 | Effect.gen(function* () { |
| 46 | const cluster = yield* AWS.RDS.DBCluster("ListCluster", { |
| 47 | engine: "aurora-postgresql", |
| 48 | masterUsername: "alchemy", |
| 49 | manageMasterUserPassword: true, |
| 50 | }); |
| 51 | return yield* DBClusterEndpoint("ListEndpoint", { |
| 52 | dbClusterIdentifier: cluster.dbClusterIdentifier, |
| 53 | endpointType: "READER", |
| 54 | }); |
| 55 | }), |
| 56 | ); |
| 57 | |
| 58 | const provider = yield* Provider.findProvider(DBClusterEndpoint); |
| 59 | const all = yield* provider.list(); |
| 60 | |
| 61 | expect( |
| 62 | all.some( |
| 63 | (e) => |
| 64 | e.dbClusterEndpointIdentifier === |
| 65 | endpoint.dbClusterEndpointIdentifier, |
| 66 | ), |
| 67 | ).toBe(true); |
| 68 | |
| 69 | yield* stack.destroy(); |
| 70 | }), |
| 71 | { tags: ["provider:aws", "provider:aws:rds", "live"] }, |
| 72 | ); |