1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as dataplex from "@distilled.cloud/gcp/dataplex_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7import * as Schedule from "effect/Schedule";
8import { withDataplexSlot } from "./quota.ts";
9
10const { test } = Test.make({ providers: GCP.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17const waitUntilGone = (name: string) =>
18 dataplex.getProjectsLocationsGlossariesTerms({ 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
28test.provider.skipIf(!!process.env.FAST)(
29 "create, update, and delete a glossary term",
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: "terms parent",
39 labels: { env: "test" },
40 });
41 const term = yield* GCP.Dataplex.GlossariesTerm("Customer", {
42 glossary: glossary.name,
43 displayName: "Customer",
44 description: "a paying account",
45 labels: { env: "test" },
46 });
47 return { glossary, term };
48 }),
49 );
50
51 expect(created.term.name).toContain("/terms/");
52 expect(created.term.termId).toEqual(expect.any(String));
53 expect(created.term.glossary).toEqual(created.glossary.name);
54 expect(created.term.displayName).toEqual("Customer");
55 expect(created.term.description).toEqual("a paying account");
56 expect(created.term.labels).toMatchObject({ env: "test" });
57
58 const fetched = yield* dataplex.getProjectsLocationsGlossariesTerms({
59 name: created.term.name,
60 });
61 expect(fetched.name).toEqual(created.term.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: "terms parent",
75 labels: { env: "test" },
76 });
77 const term = yield* GCP.Dataplex.GlossariesTerm("Customer", {
78 glossary: glossary.name,
79 termId: created.term.termId,
80 displayName: "Customer account",
81 description: "updated term",
82 labels: { env: "prod", team: "data" },
83 });
84 return { glossary, term };
85 }),
86 );
87
88 expect(updated.term.name).toEqual(created.term.name);
89 expect(updated.term.displayName).toEqual("Customer account");
90 expect(updated.term.description).toEqual("updated term");
91 expect(updated.term.labels).toMatchObject({ env: "prod", team: "data" });
92
93 yield* stack.destroy();
94 const gone = yield* waitUntilGone(created.term.name);
95 expect(gone).toEqual("gone");
96 }).pipe(logLevel, withDataplexSlot),
97 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
98);