@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 139 lines 5.06 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as netapp from "@distilled.cloud/gcp/netapp_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Volumes need a Private Service Access connection to
15 // `netapp.servicenetworking.goog` on the `default` network (otherwise volume
16 // create fails with `Please create Service Networking connection with
17 // service 'netapp.servicenetworking.goog' ...`), and each file provisions its
18 // own 2 TiB STANDARD pool while the default regional quota
19 // (StandardStoragePoolCapacityGiBPerRegion = 2048) fits one. Set
20 // GCP_TEST_NETAPP_VOLUMES=1 on a project with both.
21 const runLifecycle = !!process.env.GCP_TEST_NETAPP_VOLUMES && !process.env.FAST;
22
23 const waitUntilGone = (name: string) =>
24 netapp.getProjectsLocationsVolumesQuotaRules({ name }).pipe(
25 Effect.as("found" as const),
26 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
27 Effect.repeat({
28 schedule: Schedule.spaced("2 seconds"),
29 until: (status) => status === "gone",
30 times: 10,
31 }),
32 );
33
34 test.provider(
35 "getProjectsLocationsVolumesQuotaRules on a missing rule fails with a typed tag",
36 (stack) =>
37 Effect.gen(function* () {
38 const { project } = yield* GcpEnvironment.current;
39
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 netapp.getProjectsLocationsVolumesQuotaRules({
44 name: `projects/${project}/locations/us-central1/volumes/alchemy-missing-volume/quotaRules/alchemy-missing-rule`,
45 }),
46 );
47 expect(error._tag).toEqual("NotFound");
48
49 const page = yield* netapp.listProjectsLocationsVolumesQuotaRules({
50 parent: `projects/${project}/locations/-/volumes/-`,
51 pageSize: 10,
52 });
53 expect((page.quotaRules ?? []).map((item) => item.name)).not.toContain(
54 `projects/${project}/locations/us-central1/volumes/alchemy-missing-volume/quotaRules/alchemy-missing-rule`,
55 );
56
57 yield* stack.destroy();
58 }).pipe(logLevel),
59 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 },
60 );
61
62 test.provider.skipIf(!runLifecycle)(
63 "create, update, and delete a quota rule",
64 (stack) =>
65 Effect.gen(function* () {
66 yield* stack.destroy();
67
68 const created = yield* stack.deploy(
69 Effect.gen(function* () {
70 const pool = yield* GCP.NetApp.StoragePool("Pool", {
71 network: "default",
72 serviceLevel: "STANDARD",
73 capacityGib: 2048,
74 labels: { env: "test" },
75 });
76 const volume = yield* GCP.NetApp.Volume("Share", {
77 storagePool: pool.name,
78 protocols: ["NFSV3"],
79 capacityGib: 100,
80 labels: { env: "test" },
81 });
82 return yield* GCP.NetApp.VolumesQuotaRule("DefaultUser", {
83 volume: volume.name,
84 type: "DEFAULT_USER_QUOTA",
85 diskLimitMib: 1024,
86 description: "alchemy-test-quota",
87 labels: { env: "test" },
88 });
89 }),
90 );
91
92 expect(created.name).toContain("/quotaRules/");
93 expect(created.diskLimitMib).toEqual(1024);
94 expect(created.labels).toMatchObject({ env: "test" });
95
96 const fetched = yield* netapp.getProjectsLocationsVolumesQuotaRules({
97 name: created.name,
98 });
99 expect(fetched.name).toEqual(created.name);
100 expect(fetched.diskLimitMib).toEqual(1024);
101 expect(fetched.labels?.env).toEqual("test");
102
103 const updated = yield* stack.deploy(
104 Effect.gen(function* () {
105 const pool = yield* GCP.NetApp.StoragePool("Pool", {
106 network: "default",
107 serviceLevel: "STANDARD",
108 capacityGib: 2048,
109 labels: { env: "test" },
110 });
111 const volume = yield* GCP.NetApp.Volume("Share", {
112 storagePool: pool.name,
113 protocols: ["NFSV3"],
114 capacityGib: 100,
115 labels: { env: "test" },
116 });
117 return yield* GCP.NetApp.VolumesQuotaRule("DefaultUser", {
118 quotaRuleId: created.quotaRuleId,
119 volume: volume.name,
120 type: "DEFAULT_USER_QUOTA",
121 diskLimitMib: 2048,
122 description: "alchemy-prod-quota",
123 labels: { env: "prod", role: "quota" },
124 });
125 }),
126 );
127
128 expect(updated.name).toEqual(created.name);
129 expect(updated.diskLimitMib).toEqual(2048);
130 expect(updated.description).toEqual("alchemy-prod-quota");
131 expect(updated.labels).toMatchObject({ env: "prod", role: "quota" });
132
133 yield* stack.destroy();
134
135 const gone = yield* waitUntilGone(created.name);
136 expect(gone).toEqual("gone");
137 }).pipe(logLevel),
138 { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 },
139 );