| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Cluster } from "@/AWS/EKS"; |
| 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 | // Ungated probe: `list()` enumerates every cluster in the ambient |
| 11 | // account/region by paginating `listClusters` (names only) and hydrating each |
| 12 | // via `readCluster` (describeCluster + listTagsForResource). It needs no |
| 13 | // deployed resource — in a clean account/region it returns `[]`, otherwise a |
| 14 | // well-formed array of full Cluster Attributes. This proves the enumeration |
| 15 | // wiring (listClusters -> describeCluster) compiles and runs live without |
| 16 | // paying the ~10-minute control-plane create. |
| 17 | test.provider( |
| 18 | "list returns a well-formed array of clusters", |
| 19 | (stack) => |
| 20 | Effect.gen(function* () { |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const provider = yield* Provider.findProvider(Cluster); |
| 24 | const all = yield* provider.list(); |
| 25 | |
| 26 | expect(Array.isArray(all)).toBe(true); |
| 27 | for (const cluster of all) { |
| 28 | expect(typeof cluster.clusterArn).toBe("string"); |
| 29 | expect(typeof cluster.clusterName).toBe("string"); |
| 30 | expect(typeof cluster.roleArn).toBe("string"); |
| 31 | } |
| 32 | }), |
| 33 | { tags: ["provider:aws", "provider:aws:eks", "live"] }, |
| 34 | ); |
| 35 | |
| 36 | // Full deploy test: an EKS control plane takes ~10+ minutes to provision, far |
| 37 | // too heavy for CI. Gate the deploy behind env vars supplying a pre-existing |
| 38 | // IAM role ARN (AWS_TEST_EKS_ROLE_ARN) and at least two subnet IDs |
| 39 | // (AWS_TEST_EKS_SUBNET_IDS, comma-separated). An account with that standing |
| 40 | // infrastructure runs this unchanged: it deploys a cluster, waits for ACTIVE, |
| 41 | // asserts it appears in the exhaustively-paginated `list()`, then tears down. |
| 42 | test.provider.skipIf( |
| 43 | !process.env.AWS_TEST_EKS_ROLE_ARN || !process.env.AWS_TEST_EKS_SUBNET_IDS, |
| 44 | )( |
| 45 | "list enumerates the deployed cluster", |
| 46 | (stack) => |
| 47 | Effect.gen(function* () { |
| 48 | yield* stack.destroy(); |
| 49 | |
| 50 | const roleArn = process.env.AWS_TEST_EKS_ROLE_ARN!; |
| 51 | const subnetIds = process.env.AWS_TEST_EKS_SUBNET_IDS!.split(","); |
| 52 | |
| 53 | const cluster = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | return yield* Cluster("ListCluster", { |
| 56 | clusterName: "alchemy-test-eks-list", |
| 57 | roleArn, |
| 58 | resourcesVpcConfig: { |
| 59 | subnetIds, |
| 60 | endpointPublicAccess: true, |
| 61 | endpointPrivateAccess: true, |
| 62 | }, |
| 63 | }); |
| 64 | }), |
| 65 | ); |
| 66 | |
| 67 | const provider = yield* Provider.findProvider(Cluster); |
| 68 | const all = yield* provider.list(); |
| 69 | |
| 70 | expect(all.some((c) => c.clusterName === cluster.clusterName)).toBe(true); |
| 71 | |
| 72 | yield* stack.destroy(); |
| 73 | }), |
| 74 | { tags: ["provider:aws", "provider:aws:eks", "live"], timeout: 1_800_000 }, |
| 75 | ); |