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 dataplex from "@distilled.cloud/gcp/dataplex_v1"; |
| 5 | import * as Output from "alchemy/Output"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { withDataplexSlot } from "./quota.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const waitUntilGone = (name: string) => |
| 16 | dataplex.getProjectsLocationsLakesZonesAssets({ name }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("2 seconds"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | // A lake (~2.5 min) plus a bucket asset (~1.5 min), then teardown of both, |
| 27 | // runs past 5 minutes. |
| 28 | test.provider.skipIf(!process.env.GCP_TEST_SLOW || !!process.env.FAST)( |
| 29 | "create, update, and delete a lake asset", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const created = yield* stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | const bucket = yield* GCP.Storage.Bucket("LandingData", { |
| 37 | location: "US-CENTRAL1", |
| 38 | forceDestroy: true, |
| 39 | labels: { env: "test" }, |
| 40 | }); |
| 41 | const lake = yield* GCP.Dataplex.Lake("Warehouse", { |
| 42 | location: "us-central1", |
| 43 | labels: { env: "test" }, |
| 44 | }); |
| 45 | const zone = yield* GCP.Dataplex.LakesZone("Landing", { |
| 46 | lake: lake.name, |
| 47 | type: "RAW", |
| 48 | locationType: "SINGLE_REGION", |
| 49 | discoverySpec: { enabled: false }, |
| 50 | labels: { env: "test" }, |
| 51 | }); |
| 52 | const asset = yield* GCP.Dataplex.LakesAsset("RawBucket", { |
| 53 | zone: zone.name, |
| 54 | displayName: "landing bucket", |
| 55 | labels: { env: "test" }, |
| 56 | resourceSpec: { |
| 57 | type: "STORAGE_BUCKET", |
| 58 | name: Output.interpolate`projects/${bucket.projectNumber}/buckets/${bucket.bucketName}`, |
| 59 | }, |
| 60 | discoverySpec: { enabled: false }, |
| 61 | }); |
| 62 | return { bucket, lake, zone, asset }; |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.asset.name).toContain("/assets/"); |
| 67 | expect(created.asset.assetId).toEqual(expect.any(String)); |
| 68 | expect(created.asset.zone).toEqual(created.zone.name); |
| 69 | expect(created.asset.resourceType).toEqual("STORAGE_BUCKET"); |
| 70 | expect(created.asset.labels).toMatchObject({ env: "test" }); |
| 71 | |
| 72 | const fetched = yield* dataplex.getProjectsLocationsLakesZonesAssets({ |
| 73 | name: created.asset.name, |
| 74 | }); |
| 75 | expect(fetched.name).toEqual(created.asset.name); |
| 76 | expect(fetched.labels?.env).toEqual("test"); |
| 77 | expect(fetched.resourceSpec?.type).toEqual("STORAGE_BUCKET"); |
| 78 | |
| 79 | const updated = yield* stack.deploy( |
| 80 | Effect.gen(function* () { |
| 81 | const bucket = yield* GCP.Storage.Bucket("LandingData", { |
| 82 | bucketName: created.bucket.bucketName, |
| 83 | location: "US-CENTRAL1", |
| 84 | forceDestroy: true, |
| 85 | labels: { env: "test" }, |
| 86 | }); |
| 87 | const lake = yield* GCP.Dataplex.Lake("Warehouse", { |
| 88 | lakeId: created.lake.lakeId, |
| 89 | location: "us-central1", |
| 90 | labels: { env: "test" }, |
| 91 | }); |
| 92 | const zone = yield* GCP.Dataplex.LakesZone("Landing", { |
| 93 | lake: lake.name, |
| 94 | zoneId: created.zone.zoneId, |
| 95 | type: "RAW", |
| 96 | locationType: "SINGLE_REGION", |
| 97 | discoverySpec: { enabled: false }, |
| 98 | labels: { env: "test" }, |
| 99 | }); |
| 100 | const asset = yield* GCP.Dataplex.LakesAsset("RawBucket", { |
| 101 | zone: zone.name, |
| 102 | assetId: created.asset.assetId, |
| 103 | displayName: "landing bucket b", |
| 104 | description: "updated asset", |
| 105 | labels: { env: "prod", team: "data" }, |
| 106 | resourceSpec: { |
| 107 | type: "STORAGE_BUCKET", |
| 108 | name: Output.interpolate`projects/${bucket.projectNumber}/buckets/${bucket.bucketName}`, |
| 109 | }, |
| 110 | discoverySpec: { enabled: false }, |
| 111 | }); |
| 112 | return { bucket, lake, zone, asset }; |
| 113 | }), |
| 114 | ); |
| 115 | |
| 116 | expect(updated.asset.name).toEqual(created.asset.name); |
| 117 | expect(updated.asset.displayName).toEqual("landing bucket b"); |
| 118 | expect(updated.asset.description).toEqual("updated asset"); |
| 119 | expect(updated.asset.labels).toMatchObject({ env: "prod", team: "data" }); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | const gone = yield* waitUntilGone(created.asset.name); |
| 123 | expect(gone).toEqual("gone"); |
| 124 | }).pipe(logLevel, withDataplexSlot), |
| 125 | { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 }, |
| 126 | ); |