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
17// Volumes need a Private Service Access connection to
18// `netapp.servicenetworking.goog` on the `default` network (otherwise volume
19// create fails with `Please create Service Networking connection with
20// service 'netapp.servicenetworking.goog' ...`), and each file provisions its
21// own 2 TiB STANDARD pool while the default regional quota
22// (StandardStoragePoolCapacityGiBPerRegion = 2048) fits one. Set
23// GCP_TEST_NETAPP_VOLUMES=1 on a project with both.
24const runLifecycle = !!process.env.GCP_TEST_NETAPP_VOLUMES && !process.env.FAST;
25
26const waitUntilGone = (name: string) =>
27 netapp.getProjectsLocationsVolumes({ name }).pipe(
28 Effect.as("found" as const),
29 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
30 Effect.repeat({
31 schedule: Schedule.spaced("2 seconds"),
32 until: (status) => status === "gone",
33 times: 10,
34 }),
35 );
36
37test.provider(
38 "getProjectsLocationsVolumes on a missing volume fails with a typed tag",
39 (stack) =>
40 Effect.gen(function* () {
41 const { project } = yield* GcpEnvironment.current;
42
43 yield* stack.destroy();
44
45 const error = yield* Effect.flip(
46 netapp.getProjectsLocationsVolumes({
47 name: `projects/${project}/locations/us-central1/volumes/alchemy-netapp-missing`,
48 }),
49 );
50 expect(error._tag).toEqual("NotFound");
51
52 const page = yield* netapp.listProjectsLocationsVolumes({
53 parent: `projects/${project}/locations/-`,
54 pageSize: 10,
55 });
56 expect((page.volumes ?? []).map((item) => item.name)).not.toContain(
57 `projects/${project}/locations/us-central1/volumes/alchemy-netapp-missing`,
58 );
59
60 yield* stack.destroy();
61 }).pipe(logLevel),
62 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 },
63);
64
65test.provider.skipIf(!runLifecycle)(
66 "create, update, and delete a volume",
67 (stack) =>
68 Effect.gen(function* () {
69 yield* stack.destroy();
70
71 const created = yield* stack.deploy(
72 Effect.gen(function* () {
73 const pool = yield* GCP.NetApp.StoragePool("Pool", {
74 network: "default",
75 serviceLevel: "STANDARD",
76 capacityGib: 2048,
77 labels: { env: "test" },
78 });
79 return yield* GCP.NetApp.Volume("Share", {
80 storagePool: pool.name,
81 protocols: ["NFSV3"],
82 capacityGib: 100,
83 description: "alchemy-test-volume",
84 labels: { env: "test" },
85 });
86 }),
87 );
88
89 expect(created.name).toContain("/volumes/");
90 expect(created.protocols).toContain("NFSV3");
91 expect(created.capacityGib).toEqual("100");
92 expect(created.labels).toMatchObject({ env: "test" });
93
94 const fetched = yield* netapp.getProjectsLocationsVolumes({
95 name: created.name,
96 });
97 expect(fetched.name).toEqual(created.name);
98 expect(fetched.labels?.env).toEqual("test");
99
100 const updated = yield* stack.deploy(
101 Effect.gen(function* () {
102 const pool = yield* GCP.NetApp.StoragePool("Pool", {
103 network: "default",
104 serviceLevel: "STANDARD",
105 capacityGib: 2048,
106 labels: { env: "test" },
107 });
108 return yield* GCP.NetApp.Volume("Share", {
109 volumeId: created.volumeId,
110 storagePool: pool.name,
111 protocols: ["NFSV3"],
112 capacityGib: 100,
113 description: "alchemy-prod-volume",
114 labels: { env: "prod", role: "nfs" },
115 });
116 }),
117 );
118
119 expect(updated.name).toEqual(created.name);
120 expect(updated.description).toEqual("alchemy-prod-volume");
121 expect(updated.labels).toMatchObject({ env: "prod", role: "nfs" });
122
123 yield* stack.destroy();
124
125 const gone = yield* waitUntilGone(created.name);
126 expect(gone).toEqual("gone");
127 }).pipe(logLevel),
128 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 },
129);