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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as biglake from "@distilled.cloud/gcp/biglake_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { location, logLevel, currentProject, waitUntilGone } from "./common.ts"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: GCP.providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "getProjectsLocationsCatalogsDatabases on a missing database fails with a typed tag", |
| 12 | (stack) => |
| 13 | Effect.gen(function* () { |
| 14 | const project = yield* currentProject; |
| 15 | |
| 16 | yield* stack.destroy(); |
| 17 | |
| 18 | const error = yield* Effect.flip( |
| 19 | biglake.getProjectsLocationsCatalogsDatabases({ |
| 20 | name: `projects/${project}/locations/${location}/catalogs/missing/databases/alchemy-missing`, |
| 21 | }), |
| 22 | ); |
| 23 | expect(error._tag).toEqual("BigLakeResourceNotFound"); |
| 24 | |
| 25 | yield* stack.destroy(); |
| 26 | }).pipe(logLevel), |
| 27 | { tags: ["provider:gcp", "provider:gcp:biglake", "live"], timeout: 90_000 }, |
| 28 | ); |
| 29 | |
| 30 | test.provider( |
| 31 | "create, update, and delete a catalog database", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const bucket = yield* stack.deploy( |
| 37 | Effect.gen(function* () { |
| 38 | return yield* GCP.Storage.Bucket("HiveMeta", { |
| 39 | location: "US-CENTRAL1", |
| 40 | forceDestroy: true, |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | const created = yield* stack.deploy( |
| 46 | Effect.gen(function* () { |
| 47 | const catalog = yield* GCP.BigLake.Catalog("Lake", { location }); |
| 48 | const database = yield* GCP.BigLake.CatalogsDatabase("Warehouse", { |
| 49 | catalog: catalog.name, |
| 50 | locationUri: `gs://${bucket.bucketName}/warehouse`, |
| 51 | parameters: { owner: "analytics" }, |
| 52 | }); |
| 53 | return { catalog, database }; |
| 54 | }), |
| 55 | ); |
| 56 | |
| 57 | expect(created.database.name).toContain("/databases/"); |
| 58 | expect(created.database.catalog).toEqual(created.catalog.name); |
| 59 | expect(created.database.type).toEqual("HIVE"); |
| 60 | expect(created.database.parameters).toMatchObject({ owner: "analytics" }); |
| 61 | expect(created.database.locationUri).toEqual(`gs://${bucket.bucketName}/warehouse`); |
| 62 | |
| 63 | const fetched = yield* biglake.getProjectsLocationsCatalogsDatabases({ |
| 64 | name: created.database.name, |
| 65 | }); |
| 66 | expect(fetched.name).toEqual(created.database.name); |
| 67 | expect(fetched.type).toEqual("HIVE"); |
| 68 | expect(fetched.hiveOptions?.parameters?.owner).toEqual("analytics"); |
| 69 | expect(fetched.hiveOptions?.parameters?.["alchemy-id"]).toEqual(expect.any(String)); |
| 70 | |
| 71 | const updated = yield* stack.deploy( |
| 72 | Effect.gen(function* () { |
| 73 | const catalog = yield* GCP.BigLake.Catalog("Lake", { |
| 74 | catalogId: created.catalog.catalogId, |
| 75 | location, |
| 76 | }); |
| 77 | const database = yield* GCP.BigLake.CatalogsDatabase("Warehouse", { |
| 78 | catalog: catalog.name, |
| 79 | databaseId: created.database.databaseId, |
| 80 | locationUri: `gs://${bucket.bucketName}/warehouse-v2`, |
| 81 | parameters: { owner: "data", env: "prod" }, |
| 82 | }); |
| 83 | return { catalog, database }; |
| 84 | }), |
| 85 | ); |
| 86 | |
| 87 | expect(updated.database.name).toEqual(created.database.name); |
| 88 | expect(updated.database.locationUri).toEqual(`gs://${bucket.bucketName}/warehouse-v2`); |
| 89 | expect(updated.database.parameters).toMatchObject({ |
| 90 | owner: "data", |
| 91 | env: "prod", |
| 92 | }); |
| 93 | |
| 94 | yield* stack.destroy(); |
| 95 | const gone = yield* waitUntilGone( |
| 96 | biglake.getProjectsLocationsCatalogsDatabases({ |
| 97 | name: created.database.name, |
| 98 | }), |
| 99 | ); |
| 100 | expect(gone).toEqual("gone"); |
| 101 | }).pipe(logLevel), |
| 102 | { tags: ["provider:gcp", "provider:gcp:biglake", "live"], timeout: 120_000 }, |
| 103 | ); |