| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as oracle from "@distilled.cloud/gcp/oracledatabase_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | // Oracle Database@Google Cloud is not enabled in the test project |
| 18 | // (ServiceDisabled) and needs an Oracle Cloud subscription. Set |
| 19 | // GCP_TEST_ORACLE=1 in a project that has one. |
| 20 | const runLifecycle = !!process.env.GCP_TEST_ORACLE && !process.env.FAST; |
| 21 | |
| 22 | const SSH_KEY = |
| 23 | "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl alchemy-test"; |
| 24 | |
| 25 | const waitUntilGone = (name: string) => |
| 26 | oracle.getProjectsLocationsExadbVmClusters({ name }).pipe( |
| 27 | Effect.as("found" as const), |
| 28 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 29 | Effect.repeat({ |
| 30 | schedule: Schedule.spaced("2 seconds"), |
| 31 | until: (status) => status === "gone", |
| 32 | times: 10, |
| 33 | }), |
| 34 | ); |
| 35 | |
| 36 | test.provider.skipIf(runLifecycle)( |
| 37 | "getProjectsLocationsExadbVmClusters without Oracle Database enabled fails with ServiceDisabled", |
| 38 | (stack) => |
| 39 | Effect.gen(function* () { |
| 40 | const { project } = yield* GcpEnvironment.current; |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const error = yield* Effect.flip( |
| 45 | oracle.getProjectsLocationsExadbVmClusters({ |
| 46 | name: `projects/${project}/locations/us-central1/exadbVmClusters/alchemy-oracle-missing`, |
| 47 | }), |
| 48 | ); |
| 49 | expect(error._tag).toEqual("ServiceDisabled"); |
| 50 | |
| 51 | yield* stack.destroy(); |
| 52 | }).pipe(logLevel), |
| 53 | { |
| 54 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 55 | timeout: 90_000, |
| 56 | }, |
| 57 | ); |
| 58 | |
| 59 | test.provider.skipIf(!runLifecycle)( |
| 60 | "create, update, and delete an exadb vm cluster", |
| 61 | (stack) => |
| 62 | Effect.gen(function* () { |
| 63 | const { project } = yield* GcpEnvironment.current; |
| 64 | |
| 65 | yield* stack.destroy(); |
| 66 | |
| 67 | const created = yield* stack.deploy( |
| 68 | Effect.gen(function* () { |
| 69 | const vault = yield* GCP.OracleDatabase.ExascaleDbStorageVault( |
| 70 | "Vault", |
| 71 | { |
| 72 | displayName: "alchemyvault", |
| 73 | totalSizeGbs: 300, |
| 74 | }, |
| 75 | ); |
| 76 | return yield* GCP.OracleDatabase.ExadbVmCluster("ExaVm", { |
| 77 | location: "us-central1", |
| 78 | displayName: "alchemyexavm", |
| 79 | odbSubnet: `projects/${project}/locations/us-central1/odbNetworks/missing/odbSubnets/client`, |
| 80 | backupOdbSubnet: `projects/${project}/locations/us-central1/odbNetworks/missing/odbSubnets/backup`, |
| 81 | gridImageId: "19.0.0.0", |
| 82 | hostnamePrefix: "exavm", |
| 83 | sshPublicKeys: [SSH_KEY], |
| 84 | exascaleDbStorageVault: vault.name, |
| 85 | enabledEcpuCountPerNode: 8, |
| 86 | nodeCount: 2, |
| 87 | properties: { |
| 88 | vmFileSystemStorage: { sizeInGbsPerNode: 180 }, |
| 89 | shapeAttribute: "SMART_STORAGE", |
| 90 | }, |
| 91 | labels: { env: "test" }, |
| 92 | }); |
| 93 | }), |
| 94 | ); |
| 95 | |
| 96 | expect(created.name).toContain("/exadbVmClusters/"); |
| 97 | expect(created.exadbVmClusterId).toEqual(expect.any(String)); |
| 98 | expect(created.labels).toMatchObject({ env: "test" }); |
| 99 | |
| 100 | const fetched = yield* oracle.getProjectsLocationsExadbVmClusters({ |
| 101 | name: created.name, |
| 102 | }); |
| 103 | expect(fetched.name).toEqual(created.name); |
| 104 | |
| 105 | yield* stack.destroy(); |
| 106 | |
| 107 | const gone = yield* waitUntilGone(created.name); |
| 108 | expect(gone).toEqual("gone"); |
| 109 | }).pipe(logLevel), |
| 110 | { |
| 111 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 112 | timeout: 120_000, |
| 113 | }, |
| 114 | ); |