@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 99 lines 3.87 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, externalVpnGateway: string) =>
14 compute.getExternalVpnGateways({ project, externalVpnGateway }).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 an external VPN gateway",
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.ExternalVpnGateway("Peer", {
33 description: "alchemy test external vpn",
34 redundancyType: "TWO_IPS_REDUNDANCY",
35 interfaces: [
36 { id: 0, ipAddress: "203.0.113.1" },
37 { id: 1, ipAddress: "203.0.113.2" },
38 ],
39 labels: { env: "test" },
40 });
41 }),
42 );
43
44 expect(created.externalVpnGatewayName).toEqual(expect.any(String));
45 expect(created.description).toEqual("alchemy test external vpn");
46 expect(created.redundancyType).toEqual("TWO_IPS_REDUNDANCY");
47 expect(created.labels).toMatchObject({ env: "test" });
48 expect(created.interfaces).toHaveLength(2);
49 expect(created.interfaces[0]?.ipAddress).toEqual("203.0.113.1");
50 expect(created.interfaces[1]?.ipAddress).toEqual("203.0.113.2");
51
52 const fetched = yield* compute.getExternalVpnGateways({
53 project: created.project,
54 externalVpnGateway: created.externalVpnGatewayName,
55 });
56 expect(fetched.name).toEqual(created.externalVpnGatewayName);
57 expect(fetched.description).toEqual("alchemy test external vpn");
58 expect(fetched.redundancyType).toEqual("TWO_IPS_REDUNDANCY");
59 expect(fetched.labels?.env).toEqual("test");
60 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
61 expect(fetched.interfaces?.[0]?.ipAddress).toEqual("203.0.113.1");
62 expect(fetched.interfaces?.[1]?.ipAddress).toEqual("203.0.113.2");
63
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 return yield* GCP.Compute.ExternalVpnGateway("Peer", {
67 externalVpnGatewayName: created.externalVpnGatewayName,
68 description: "alchemy test external vpn",
69 redundancyType: "TWO_IPS_REDUNDANCY",
70 interfaces: [
71 { id: 0, ipAddress: "203.0.113.1" },
72 { id: 1, ipAddress: "203.0.113.2" },
73 ],
74 labels: { env: "prod", role: "vpn" },
75 });
76 }),
77 );
78
79 expect(updated.externalVpnGatewayName).toEqual(created.externalVpnGatewayName);
80 expect(updated.externalVpnGatewayId).toEqual(created.externalVpnGatewayId);
81 expect(updated.labels).toMatchObject({
82 env: "prod",
83 role: "vpn",
84 });
85
86 const fetchedUpdated = yield* compute.getExternalVpnGateways({
87 project: updated.project,
88 externalVpnGateway: updated.externalVpnGatewayName,
89 });
90 expect(fetchedUpdated.labels?.env).toEqual("prod");
91 expect(fetchedUpdated.labels?.role).toEqual("vpn");
92
93 yield* stack.destroy();
94
95 const gone = yield* waitUntilGone(created.project, created.externalVpnGatewayName);
96 expect(gone).toEqual("gone");
97 }).pipe(logLevel),
98 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
99 );