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.getProjectsLocationsHostGroups({ 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 "getProjectsLocationsHostGroups on a missing group 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.getProjectsLocationsHostGroups({
38 name: `projects/${project}/locations/us-central1/hostGroups/alchemy-netapp-missing`,
39 }),
40 );
41 expect(error._tag).toEqual("NotFound");
42
43 const page = yield* netapp.listProjectsLocationsHostGroups({
44 parent: `projects/${project}/locations/-`,
45 pageSize: 10,
46 });
47 expect((page.hostGroups ?? []).map((item) => item.name)).not.toContain(
48 `projects/${project}/locations/us-central1/hostGroups/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 host group",
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.HostGroup("Initiators", {
65 hosts: ["iqn.1993-08.org.debian:01:alchemy"],
66 description: "alchemy-test-hosts",
67 labels: { env: "test" },
68 });
69 }),
70 );
71
72 expect(created.name).toContain("/hostGroups/");
73 expect(created.hosts).toContain("iqn.1993-08.org.debian:01:alchemy");
74 expect(created.labels).toMatchObject({ env: "test" });
75
76 const fetched = yield* netapp.getProjectsLocationsHostGroups({
77 name: created.name,
78 });
79 expect(fetched.name).toEqual(created.name);
80 expect(fetched.labels?.env).toEqual("test");
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 return yield* GCP.NetApp.HostGroup("Initiators", {
85 hostGroupId: created.hostGroupId,
86 hosts: [
87 "iqn.1993-08.org.debian:01:alchemy",
88 "iqn.1993-08.org.debian:01:alchemy2",
89 ],
90 description: "alchemy-prod-hosts",
91 labels: { env: "prod", role: "iscsi" },
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.description).toEqual("alchemy-prod-hosts");
98 expect(updated.labels).toMatchObject({ env: "prod", role: "iscsi" });
99 expect(updated.hosts).toHaveLength(2);
100
101 yield* stack.destroy();
102
103 const gone = yield* waitUntilGone(created.name);
104 expect(gone).toEqual("gone");
105 }).pipe(logLevel),
106 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 120_000 },
107);