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