| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as dataplex from "@distilled.cloud/gcp/dataplex_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 { withDataplexSlot } from "./quota.ts"; |
| 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 | const waitUntilGone = (name: string) => |
| 18 | dataplex.getProjectsLocationsLakesZones({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("2 seconds"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider.skipIf(!!process.env.FAST)( |
| 29 | "create, update, and delete a lake zone", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const created = yield* stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | const lake = yield* GCP.Dataplex.Lake("Warehouse", { |
| 37 | location: "us-central1", |
| 38 | labels: { env: "test" }, |
| 39 | }); |
| 40 | const zone = yield* GCP.Dataplex.LakesZone("Landing", { |
| 41 | lake: lake.name, |
| 42 | type: "RAW", |
| 43 | locationType: "SINGLE_REGION", |
| 44 | displayName: "landing a", |
| 45 | description: "raw landing", |
| 46 | labels: { env: "test" }, |
| 47 | discoverySpec: { enabled: false }, |
| 48 | }); |
| 49 | return { lake, zone }; |
| 50 | }), |
| 51 | ); |
| 52 | |
| 53 | expect(created.zone.name).toContain("/zones/"); |
| 54 | expect(created.zone.zoneId).toEqual(expect.any(String)); |
| 55 | expect(created.zone.lake).toEqual(created.lake.name); |
| 56 | expect(created.zone.type).toEqual("RAW"); |
| 57 | expect(created.zone.locationType).toEqual("SINGLE_REGION"); |
| 58 | expect(created.zone.displayName).toEqual("landing a"); |
| 59 | expect(created.zone.labels).toMatchObject({ env: "test" }); |
| 60 | expect(created.zone.discoveryEnabled).toEqual(false); |
| 61 | |
| 62 | const fetched = yield* dataplex.getProjectsLocationsLakesZones({ |
| 63 | name: created.zone.name, |
| 64 | }); |
| 65 | expect(fetched.name).toEqual(created.zone.name); |
| 66 | expect(fetched.labels?.env).toEqual("test"); |
| 67 | expect(fetched.type).toEqual("RAW"); |
| 68 | |
| 69 | const updated = yield* stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | const lake = yield* GCP.Dataplex.Lake("Warehouse", { |
| 72 | lakeId: created.lake.lakeId, |
| 73 | location: "us-central1", |
| 74 | labels: { env: "test" }, |
| 75 | }); |
| 76 | const zone = yield* GCP.Dataplex.LakesZone("Landing", { |
| 77 | lake: lake.name, |
| 78 | zoneId: created.zone.zoneId, |
| 79 | type: "RAW", |
| 80 | locationType: "SINGLE_REGION", |
| 81 | displayName: "landing b", |
| 82 | description: "raw landing b", |
| 83 | labels: { env: "prod", team: "data" }, |
| 84 | discoverySpec: { enabled: false }, |
| 85 | }); |
| 86 | return { lake, zone }; |
| 87 | }), |
| 88 | ); |
| 89 | |
| 90 | expect(updated.zone.name).toEqual(created.zone.name); |
| 91 | expect(updated.zone.displayName).toEqual("landing b"); |
| 92 | expect(updated.zone.description).toEqual("raw landing b"); |
| 93 | expect(updated.zone.labels).toMatchObject({ env: "prod", team: "data" }); |
| 94 | |
| 95 | yield* stack.destroy(); |
| 96 | const gone = yield* waitUntilGone(created.zone.name); |
| 97 | expect(gone).toEqual("gone"); |
| 98 | }).pipe(logLevel, withDataplexSlot), |
| 99 | { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 }, |
| 100 | ); |