1import { GcpEnvironment } from "@/GCP/Environment";
2import * as GCP from "@/GCP";
3import * as Test from "@/Test/Alchemy";
4import * as netapp from "@distilled.cloud/gcp/netapp_v1";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import { MinimumLogLevel } from "effect/References";
8import * as Schedule from "effect/Schedule";
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 netapp.getProjectsLocationsStoragePools({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28test.provider(
29 "getProjectsLocationsStoragePools on a missing pool fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 netapp.getProjectsLocationsStoragePools({
38 name: `projects/${project}/locations/us-central1/storagePools/alchemy-netapp-missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 const page = yield* netapp.listProjectsLocationsStoragePools({
44 parent: `projects/${project}/locations/-`,
45 pageSize: 10,
46 });
47 expect((page.storagePools ?? []).map((item) => item.name)).not.toContain(
48 `projects/${project}/locations/us-central1/storagePools/alchemy-netapp-missing`,
49 );
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 },
54);
55
56test.provider(
57 "create, update, and delete a storage pool",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.NetApp.StoragePool("Pool", {
65 network: "default",
66 serviceLevel: "STANDARD",
67 capacityGib: 2048,
68 description: "alchemy-test-pool",
69 labels: { env: "test" },
70 });
71 }),
72 );
73
74 expect(created.name).toContain("/storagePools/");
75 expect(created.serviceLevel).toEqual("STANDARD");
76 expect(created.capacityGib).toEqual("2048");
77 expect(created.labels).toMatchObject({ env: "test" });
78
79 const fetched = yield* netapp.getProjectsLocationsStoragePools({
80 name: created.name,
81 });
82 expect(fetched.name).toEqual(created.name);
83 expect(fetched.serviceLevel).toEqual("STANDARD");
84 expect(fetched.labels?.env).toEqual("test");
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 return yield* GCP.NetApp.StoragePool("Pool", {
89 storagePoolId: created.storagePoolId,
90 network: "default",
91 serviceLevel: "STANDARD",
92 capacityGib: 2048,
93 description: "alchemy-prod-pool",
94 labels: { env: "prod", role: "nfs" },
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.description).toEqual("alchemy-prod-pool");
101 expect(updated.labels).toMatchObject({ env: "prod", role: "nfs" });
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 },
109);