| 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.getProjectsLocationsCloudVmClusters({ 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 | "getProjectsLocationsCloudVmClusters 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.getProjectsLocationsCloudVmClusters({ |
| 46 | name: `projects/${project}/locations/us-central1/cloudVmClusters/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 a cloud 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 infra = yield* GCP.OracleDatabase.CloudExadataInfrastructure( |
| 70 | "Exa", |
| 71 | { |
| 72 | displayName: "alchemy-test-exa", |
| 73 | shape: "Exadata.X9M", |
| 74 | computeCount: 2, |
| 75 | storageCount: 3, |
| 76 | }, |
| 77 | ); |
| 78 | return yield* GCP.OracleDatabase.CloudVmCluster("Vms", { |
| 79 | location: "us-central1", |
| 80 | exadataInfrastructure: infra.name, |
| 81 | network: "default", |
| 82 | cidr: "10.10.0.0/24", |
| 83 | backupSubnetCidr: "10.10.1.0/24", |
| 84 | licenseType: "LICENSE_INCLUDED", |
| 85 | cpuCoreCount: 4, |
| 86 | giVersion: "19.0.0.0", |
| 87 | hostnamePrefix: "exa", |
| 88 | sshPublicKeys: [SSH_KEY], |
| 89 | labels: { env: "test" }, |
| 90 | }); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(created.name).toContain("/cloudVmClusters/"); |
| 95 | expect(created.cloudVmClusterId).toEqual(expect.any(String)); |
| 96 | expect(created.labels).toMatchObject({ env: "test" }); |
| 97 | |
| 98 | const fetched = yield* oracle.getProjectsLocationsCloudVmClusters({ |
| 99 | name: created.name, |
| 100 | }); |
| 101 | expect(fetched.name).toEqual(created.name); |
| 102 | |
| 103 | yield* stack.destroy(); |
| 104 | |
| 105 | const gone = yield* waitUntilGone(created.name); |
| 106 | expect(gone).toEqual("gone"); |
| 107 | }).pipe(logLevel), |
| 108 | { |
| 109 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 110 | timeout: 120_000, |
| 111 | }, |
| 112 | ); |