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

main
ts 133 lines 5.02 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as biglake from "@distilled.cloud/gcp/biglake_v1";
5 import * as Effect from "effect/Effect";
6 import { location, logLevel, currentProject, waitUntilGone } from "./common.ts";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 test.provider(
11 "getProjectsLocationsCatalogsDatabasesTables on a missing table 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.getProjectsLocationsCatalogsDatabasesTables({
20 name: `projects/${project}/locations/${location}/catalogs/missing/databases/missing/tables/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
30 test.provider(
31 "create, update, and delete a catalog database table",
32 (stack) =>
33 Effect.gen(function* () {
34 yield* stack.destroy();
35
36 const bucket = yield* stack.deploy(
37 Effect.gen(function* () {
38 return yield* GCP.Storage.Bucket("HiveTable", {
39 location: "US-CENTRAL1",
40 forceDestroy: true,
41 });
42 }),
43 );
44
45 const created = yield* stack.deploy(
46 Effect.gen(function* () {
47 const catalog = yield* GCP.BigLake.Catalog("Lake", { location });
48 const database = yield* GCP.BigLake.CatalogsDatabase("Warehouse", {
49 catalog: catalog.name,
50 locationUri: `gs://${bucket.bucketName}/warehouse`,
51 });
52 const table = yield* GCP.BigLake.CatalogsDatabasesTable("Events", {
53 database: database.name,
54 hiveOptions: {
55 tableType: "MANAGED_TABLE",
56 storageDescriptor: {
57 locationUri: `gs://${bucket.bucketName}/events`,
58 inputFormat: "org.apache.hadoop.mapred.SequenceFileInputFormat",
59 outputFormat: "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
60 },
61 parameters: { owner: "analytics" },
62 },
63 });
64 return { catalog, database, table };
65 }),
66 );
67
68 expect(created.table.name).toContain("/tables/");
69 expect(created.table.database).toEqual(created.database.name);
70 expect(created.table.type).toEqual("HIVE");
71 expect(created.table.tableType).toEqual("MANAGED_TABLE");
72 expect(created.table.parameters).toMatchObject({ owner: "analytics" });
73 expect(created.table.storageDescriptor?.locationUri).toEqual(
74 `gs://${bucket.bucketName}/events`,
75 );
76
77 const fetched = yield* biglake.getProjectsLocationsCatalogsDatabasesTables({
78 name: created.table.name,
79 });
80 expect(fetched.name).toEqual(created.table.name);
81 expect(fetched.type).toEqual("HIVE");
82 expect(fetched.hiveOptions?.tableType).toEqual("MANAGED_TABLE");
83 expect(fetched.hiveOptions?.parameters?.owner).toEqual("analytics");
84 expect(fetched.hiveOptions?.parameters?.["alchemy-id"]).toEqual(expect.any(String));
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 const catalog = yield* GCP.BigLake.Catalog("Lake", {
89 catalogId: created.catalog.catalogId,
90 location,
91 });
92 const database = yield* GCP.BigLake.CatalogsDatabase("Warehouse", {
93 catalog: catalog.name,
94 databaseId: created.database.databaseId,
95 locationUri: `gs://${bucket.bucketName}/warehouse`,
96 });
97 const table = yield* GCP.BigLake.CatalogsDatabasesTable("Events", {
98 database: database.name,
99 tableId: created.table.tableId,
100 hiveOptions: {
101 tableType: "EXTERNAL_TABLE",
102 storageDescriptor: {
103 locationUri: `gs://${bucket.bucketName}/events-v2`,
104 inputFormat: "org.apache.hadoop.mapred.SequenceFileInputFormat",
105 outputFormat: "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
106 },
107 parameters: { owner: "data", env: "prod" },
108 },
109 });
110 return { catalog, database, table };
111 }),
112 );
113
114 expect(updated.table.name).toEqual(created.table.name);
115 expect(updated.table.tableType).toEqual("EXTERNAL_TABLE");
116 expect(updated.table.storageDescriptor?.locationUri).toEqual(
117 `gs://${bucket.bucketName}/events-v2`,
118 );
119 expect(updated.table.parameters).toMatchObject({
120 owner: "data",
121 env: "prod",
122 });
123
124 yield* stack.destroy();
125 const gone = yield* waitUntilGone(
126 biglake.getProjectsLocationsCatalogsDatabasesTables({
127 name: created.table.name,
128 }),
129 );
130 expect(gone).toEqual("gone");
131 }).pipe(logLevel),
132 { tags: ["provider:gcp", "provider:gcp:biglake", "live"], timeout: 120_000 },
133 );