The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { GcpEnvironment } from "@alchemy.run/gcp/Environment"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as oracle from "@distilled.cloud/gcp/oracledatabase_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | // Oracle Database@Google Cloud is not enabled in the test project |
| 15 | // (ServiceDisabled) and needs an Oracle Cloud subscription. Set |
| 16 | // GCP_TEST_ORACLE=1 in a project that has one. |
| 17 | const runLifecycle = !!process.env.GCP_TEST_ORACLE && !process.env.FAST; |
| 18 | |
| 19 | const waitUntilGone = (name: string) => |
| 20 | oracle.getProjectsLocationsAutonomousDatabases({ name }).pipe( |
| 21 | Effect.as("found" as const), |
| 22 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 23 | Effect.repeat({ |
| 24 | schedule: Schedule.spaced("2 seconds"), |
| 25 | until: (status) => status === "gone", |
| 26 | times: 10, |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | test.provider.skipIf(runLifecycle)( |
| 31 | "getProjectsLocationsAutonomousDatabases without Oracle Database enabled fails with ServiceDisabled", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | const { project } = yield* GcpEnvironment.current; |
| 35 | |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const error = yield* Effect.flip( |
| 39 | oracle.getProjectsLocationsAutonomousDatabases({ |
| 40 | name: `projects/${project}/locations/us-central1/autonomousDatabases/alchemy-oracle-missing`, |
| 41 | }), |
| 42 | ); |
| 43 | expect(error._tag).toEqual("ServiceDisabled"); |
| 44 | |
| 45 | yield* stack.destroy(); |
| 46 | }).pipe(logLevel), |
| 47 | { |
| 48 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 49 | timeout: 90_000, |
| 50 | }, |
| 51 | ); |
| 52 | |
| 53 | test.provider.skipIf(!runLifecycle)( |
| 54 | "create, update, and delete an autonomous database", |
| 55 | (stack) => |
| 56 | Effect.gen(function* () { |
| 57 | const { project } = yield* GcpEnvironment.current; |
| 58 | |
| 59 | yield* stack.destroy(); |
| 60 | |
| 61 | const created = yield* stack.deploy( |
| 62 | Effect.gen(function* () { |
| 63 | return yield* GCP.OracleDatabase.AutonomousDatabase("AppDb", { |
| 64 | location: "us-central1", |
| 65 | network: "default", |
| 66 | cidr: "10.10.0.0/24", |
| 67 | adminPassword: "AlchemyTest1!", |
| 68 | displayName: "alchemy-test-adb", |
| 69 | labels: { env: "test" }, |
| 70 | licenseType: "LICENSE_INCLUDED", |
| 71 | dbWorkload: "OLTP", |
| 72 | cpuCoreCount: 2, |
| 73 | dataStorageSizeGb: 20, |
| 74 | }); |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(created.name).toContain("/autonomousDatabases/"); |
| 79 | expect(created.autonomousDatabaseId).toEqual(expect.any(String)); |
| 80 | expect(created.location).toEqual("us-central1"); |
| 81 | expect(created.labels).toMatchObject({ env: "test" }); |
| 82 | |
| 83 | const fetched = yield* oracle.getProjectsLocationsAutonomousDatabases({ |
| 84 | name: created.name, |
| 85 | }); |
| 86 | expect(fetched.name).toEqual(created.name); |
| 87 | expect(fetched.labels?.env).toEqual("test"); |
| 88 | |
| 89 | const updated = yield* stack.deploy( |
| 90 | Effect.gen(function* () { |
| 91 | return yield* GCP.OracleDatabase.AutonomousDatabase("AppDb", { |
| 92 | autonomousDatabaseId: created.autonomousDatabaseId, |
| 93 | location: "us-central1", |
| 94 | network: "default", |
| 95 | cidr: "10.10.0.0/24", |
| 96 | licenseType: "LICENSE_INCLUDED", |
| 97 | dbWorkload: "OLTP", |
| 98 | cpuCoreCount: 2, |
| 99 | dataStorageSizeGb: 20, |
| 100 | labels: { env: "prod", role: "db" }, |
| 101 | }); |
| 102 | }), |
| 103 | ); |
| 104 | |
| 105 | expect(updated.name).toEqual(created.name); |
| 106 | expect(updated.labels).toMatchObject({ env: "prod", role: "db" }); |
| 107 | |
| 108 | yield* stack.destroy(); |
| 109 | |
| 110 | const gone = yield* waitUntilGone(created.name); |
| 111 | expect(gone).toEqual("gone"); |
| 112 | }).pipe(logLevel), |
| 113 | { |
| 114 | tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"], |
| 115 | timeout: 120_000, |
| 116 | }, |
| 117 | ); |