1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as biglake from "@distilled.cloud/gcp/biglake_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { location, logLevel, currentProject, waitUntilGone } from "./common.ts";
7
8const { test } = Test.make({ providers: GCP.providers() });
9
10test.provider(
11 "getProjectsLocationsCatalogs on a missing catalog fails with a typed tag",
12 (stack) =>
13 Effect.gen(function* () {
14 const project = yield* currentProject;
15
16 yield* stack.destroy();
17
18 const error = yield* Effect.flip(
19 biglake.getProjectsLocationsCatalogs({
20 name: `projects/${project}/locations/${location}/catalogs/alchemy-missing`,
21 }),
22 );
23 expect(error._tag).toEqual("BigLakeResourceNotFound");
24
25 yield* stack.destroy();
26 }).pipe(logLevel),
27 { tags: ["provider:gcp", "provider:gcp:biglake", "live"], timeout: 90_000 },
28);
29
30test.provider(
31 "create, update, and delete a catalog",
32 (stack) =>
33 Effect.gen(function* () {
34 const project = yield* currentProject;
35
36 yield* stack.destroy();
37
38 const created = yield* stack.deploy(
39 Effect.gen(function* () {
40 return yield* GCP.BigLake.Catalog("Lake", {
41 location,
42 });
43 }),
44 );
45
46 expect(created.name).toContain("/catalogs/");
47 expect(created.catalogId).toEqual(expect.any(String));
48 expect(created.location).toEqual(location);
49 expect(created.project).toEqual(project);
50
51 const fetched = yield* biglake.getProjectsLocationsCatalogs({
52 name: created.name,
53 });
54 expect(fetched.name).toContain(created.catalogId);
55
56 const updated = yield* stack.deploy(
57 Effect.gen(function* () {
58 return yield* GCP.BigLake.Catalog("Lake", {
59 catalogId: created.catalogId,
60 location,
61 });
62 }),
63 );
64
65 expect(updated.name).toEqual(created.name);
66 expect(updated.catalogId).toEqual(created.catalogId);
67
68 yield* stack.destroy();
69 const gone = yield* waitUntilGone(
70 biglake.getProjectsLocationsCatalogs({ name: created.name }),
71 );
72 expect(gone).toEqual("gone");
73 }).pipe(logLevel),
74 { tags: ["provider:gcp", "provider:gcp:biglake", "live"], timeout: 90_000 },
75);