@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 103 lines 3.73 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as dataplex from "@distilled.cloud/gcp/dataplex_v1";
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.getProjectsLocationsDataProducts({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("1 second"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "getProjectsLocationsDataProducts on a missing product fails with a typed tag",
28 (stack) =>
29 Effect.gen(function* () {
30 const { project } = yield* GcpEnvironment.current;
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 dataplex.getProjectsLocationsDataProducts({
35 name: `projects/${project}/locations/us-central1/dataProducts/alchemy-missing-product`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39
40 yield* stack.destroy();
41 }).pipe(logLevel, withDataplexSlot),
42 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
43 );
44
45 test.provider.skipIf(!!process.env.FAST)(
46 "create, update, and delete a data product",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const created = yield* stack.deploy(
52 Effect.gen(function* () {
53 return yield* GCP.Dataplex.DataProduct("Sales", {
54 location: "us-central1",
55 displayName: "Sales mart",
56 description: "product a",
57 ownerEmails: ["owner@example.com"],
58 labels: { env: "test" },
59 });
60 }),
61 );
62
63 expect(created.name).toContain("/dataProducts/");
64 expect(created.dataProductId).toEqual(expect.any(String));
65 expect(created.location).toEqual("us-central1");
66 expect(created.displayName).toEqual("Sales mart");
67 expect(created.description).toEqual("product a");
68 expect(created.ownerEmails).toContain("owner@example.com");
69 expect(created.labels).toMatchObject({ env: "test" });
70
71 const fetched = yield* dataplex.getProjectsLocationsDataProducts({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75 expect(fetched.labels?.env).toEqual("test");
76 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
77 true,
78 );
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 return yield* GCP.Dataplex.DataProduct("Sales", {
83 dataProductId: created.dataProductId,
84 location: "us-central1",
85 displayName: "Sales prod",
86 description: "product b",
87 ownerEmails: ["owner@example.com", "steward@example.com"],
88 labels: { env: "prod", team: "data" },
89 });
90 }),
91 );
92
93 expect(updated.name).toEqual(created.name);
94 expect(updated.displayName).toEqual("Sales prod");
95 expect(updated.description).toEqual("product b");
96 expect(updated.labels).toMatchObject({ env: "prod", team: "data" });
97
98 yield* stack.destroy();
99 const gone = yield* waitUntilGone(created.name);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel, withDataplexSlot),
102 { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 },
103 );