@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 80 lines 2.88 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as compute from "@distilled.cloud/gcp/compute_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (project: string, address: string) =>
14 compute.getGlobalAddresses({ project, address }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a global address",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.Compute.GlobalAddress("FrontendIp", {
33 description: "alchemy test global address",
34 labels: { env: "test" },
35 });
36 }),
37 );
38
39 expect(created.addressName).toEqual(expect.any(String));
40 expect(created.address).toEqual(expect.any(String));
41 expect(created.addressType).toEqual("EXTERNAL");
42 expect(created.labels).toMatchObject({ env: "test" });
43 expect(created.status).toEqual(expect.stringMatching(/RESERVED|IN_USE/));
44
45 const fetched = yield* compute.getGlobalAddresses({
46 project: created.project,
47 address: created.addressName,
48 });
49 expect(fetched.name).toEqual(created.addressName);
50 expect(fetched.address).toEqual(created.address);
51 expect(fetched.labels?.env).toEqual("test");
52
53 const updated = yield* stack.deploy(
54 Effect.gen(function* () {
55 return yield* GCP.Compute.GlobalAddress("FrontendIp", {
56 addressName: created.addressName,
57 description: "alchemy test global address",
58 labels: { env: "prod", role: "frontend" },
59 });
60 }),
61 );
62
63 expect(updated.addressName).toEqual(created.addressName);
64 expect(updated.address).toEqual(created.address);
65 expect(updated.labels).toMatchObject({ env: "prod", role: "frontend" });
66
67 const fetchedUpdated = yield* compute.getGlobalAddresses({
68 project: updated.project,
69 address: updated.addressName,
70 });
71 expect(fetchedUpdated.labels?.env).toEqual("prod");
72 expect(fetchedUpdated.labels?.role).toEqual("frontend");
73
74 yield* stack.destroy();
75
76 const gone = yield* waitUntilGone(created.project, created.addressName);
77 expect(gone).toEqual("gone");
78 }).pipe(logLevel),
79 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
80 );