| 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.getProjectsLocationsGlossaries({ name }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("1 second"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider.skipIf(!!process.env.FAST)( |
| 29 | "create, update, and delete a glossary", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const created = yield* stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | return yield* GCP.Dataplex.Glossary("BusinessTerms", { |
| 37 | location: "us-central1", |
| 38 | displayName: "glossary a", |
| 39 | description: "glossary a", |
| 40 | labels: { env: "test" }, |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | expect(created.name).toContain("/glossaries/"); |
| 46 | expect(created.glossaryId).toEqual(expect.any(String)); |
| 47 | expect(created.location).toEqual("us-central1"); |
| 48 | expect(created.displayName).toEqual("glossary a"); |
| 49 | expect(created.description).toEqual("glossary a"); |
| 50 | expect(created.labels).toMatchObject({ env: "test" }); |
| 51 | |
| 52 | const fetched = yield* dataplex.getProjectsLocationsGlossaries({ |
| 53 | name: created.name, |
| 54 | }); |
| 55 | expect(fetched.name).toEqual(created.name); |
| 56 | expect(fetched.labels?.env).toEqual("test"); |
| 57 | expect( |
| 58 | Object.keys(fetched.labels ?? {}).some((key) => |
| 59 | key.startsWith("alchemy-"), |
| 60 | ), |
| 61 | ).toEqual(true); |
| 62 | |
| 63 | const updated = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | return yield* GCP.Dataplex.Glossary("BusinessTerms", { |
| 66 | glossaryId: created.glossaryId, |
| 67 | location: "us-central1", |
| 68 | displayName: "glossary b", |
| 69 | description: "glossary b", |
| 70 | labels: { env: "prod", team: "data" }, |
| 71 | }); |
| 72 | }), |
| 73 | ); |
| 74 | |
| 75 | expect(updated.name).toEqual(created.name); |
| 76 | expect(updated.displayName).toEqual("glossary b"); |
| 77 | expect(updated.description).toEqual("glossary b"); |
| 78 | expect(updated.labels).toMatchObject({ env: "prod", team: "data" }); |
| 79 | |
| 80 | yield* stack.destroy(); |
| 81 | const gone = yield* waitUntilGone(created.name); |
| 82 | expect(gone).toEqual("gone"); |
| 83 | }).pipe(logLevel, withDataplexSlot), |
| 84 | { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 }, |
| 85 | ); |