1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as metastore from "@distilled.cloud/gcp/metastore_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7import { GcpEnvironment } from "@/GCP/Environment";
8
9const { test } = Test.make({ providers: GCP.providers() });
10
11const logLevel = Effect.provideService(
12 MinimumLogLevel,
13 process.env.DEBUG ? "Debug" : "Info",
14);
15
16test.provider(
17 "getProjectsLocationsFederations on a missing federation fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 const { project } = yield* GcpEnvironment.current;
21 yield* stack.destroy();
22
23 const error = yield* Effect.flip(
24 metastore.getProjectsLocationsFederations({
25 name: `projects/${project}/locations/us-central1/federations/alchemy-missing-federation`,
26 }),
27 );
28 expect(error._tag).toEqual("ServiceDisabled");
29
30 yield* stack.destroy();
31 }).pipe(logLevel),
32 { tags: ["provider:gcp", "provider:gcp:metastore", "live"], timeout: 90_000 },
33);
34
35test.provider(
36 "create is rejected when the Dataproc Metastore API is disabled",
37 (stack) =>
38 Effect.gen(function* () {
39 const { project } = yield* GcpEnvironment.current;
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 stack.deploy(
44 Effect.gen(function* () {
45 return yield* GCP.Metastore.Federation("Lakehouse", {
46 location: "us-central1",
47 version: "3.1.2",
48 backendMetastores: {
49 "1": {
50 name: `projects/${project}`,
51 metastoreType: "BIGQUERY",
52 },
53 },
54 labels: { env: "test" },
55 });
56 }),
57 ),
58 );
59 expect(error._tag).toEqual("ServiceDisabled");
60
61 yield* stack.destroy();
62 }).pipe(logLevel),
63 { tags: ["provider:gcp", "provider:gcp:metastore", "live"], timeout: 90_000 },
64);