| 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.getProjectsLocationsGlossariesCategories({ 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 category", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const created = yield* stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | const glossary = yield* GCP.Dataplex.Glossary("BusinessTerms", { |
| 37 | location: "us-central1", |
| 38 | displayName: "glossary", |
| 39 | labels: { env: "test" }, |
| 40 | }); |
| 41 | const category = yield* GCP.Dataplex.GlossariesCategory("Finance", { |
| 42 | glossary: glossary.name, |
| 43 | displayName: "finance", |
| 44 | description: "finance terms", |
| 45 | labels: { env: "test" }, |
| 46 | }); |
| 47 | return { glossary, category }; |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | expect(created.category.name).toContain("/categories/"); |
| 52 | expect(created.category.glossary).toEqual(created.glossary.name); |
| 53 | expect(created.category.displayName).toEqual("finance"); |
| 54 | expect(created.category.description).toEqual("finance terms"); |
| 55 | expect(created.category.labels).toMatchObject({ env: "test" }); |
| 56 | expect(created.category.parent).toEqual(created.glossary.name); |
| 57 | |
| 58 | const fetched = yield* dataplex.getProjectsLocationsGlossariesCategories({ |
| 59 | name: created.category.name, |
| 60 | }); |
| 61 | expect(fetched.name).toEqual(created.category.name); |
| 62 | expect(fetched.labels?.env).toEqual("test"); |
| 63 | expect( |
| 64 | Object.keys(fetched.labels ?? {}).some((key) => |
| 65 | key.startsWith("alchemy-"), |
| 66 | ), |
| 67 | ).toEqual(true); |
| 68 | |
| 69 | const updated = yield* stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | const glossary = yield* GCP.Dataplex.Glossary("BusinessTerms", { |
| 72 | glossaryId: created.glossary.glossaryId, |
| 73 | location: "us-central1", |
| 74 | displayName: "glossary", |
| 75 | labels: { env: "test" }, |
| 76 | }); |
| 77 | const category = yield* GCP.Dataplex.GlossariesCategory("Finance", { |
| 78 | glossary: glossary.name, |
| 79 | categoryId: created.category.categoryId, |
| 80 | displayName: "finance v2", |
| 81 | description: "finance terms v2", |
| 82 | labels: { env: "prod", team: "data" }, |
| 83 | }); |
| 84 | return { glossary, category }; |
| 85 | }), |
| 86 | ); |
| 87 | |
| 88 | expect(updated.category.name).toEqual(created.category.name); |
| 89 | expect(updated.category.displayName).toEqual("finance v2"); |
| 90 | expect(updated.category.description).toEqual("finance terms v2"); |
| 91 | expect(updated.category.labels).toMatchObject({ |
| 92 | env: "prod", |
| 93 | team: "data", |
| 94 | }); |
| 95 | |
| 96 | yield* stack.destroy(); |
| 97 | const gone = yield* waitUntilGone(created.category.name); |
| 98 | expect(gone).toEqual("gone"); |
| 99 | }).pipe(logLevel, withDataplexSlot), |
| 100 | { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 }, |
| 101 | ); |