@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 102 lines 3.83 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 import { DEFAULT_NETWORK } from "../networkQuota.ts";
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 = (project: string, region: string, vpnGatewayName: string) =>
15 compute.getVpnGateways({ project, region, vpnGateway: vpnGatewayName }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider.skipIf(!!process.env.FAST)(
26 "create, update, and delete an HA VPN gateway",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const created = yield* stack.deploy(
32 Effect.gen(function* () {
33 const gateway = yield* GCP.Compute.VpnGateway("Gateway", {
34 region: "us-central1",
35 network: DEFAULT_NETWORK,
36 description: "ha vpn",
37 labels: { env: "test" },
38 });
39 return { gateway };
40 }),
41 );
42
43 expect(created.gateway.vpnGatewayName).toEqual(expect.any(String));
44 expect(created.gateway.region).toEqual("us-central1");
45 expect(created.gateway.network).toEqual(
46 expect.stringContaining(`/networks/${DEFAULT_NETWORK}`),
47 );
48 expect(created.gateway.description).toEqual("ha vpn");
49 expect(created.gateway.labels).toMatchObject({ env: "test" });
50 expect(created.gateway.vpnInterfaces.length).toBeGreaterThanOrEqual(2);
51 expect(created.gateway.vpnInterfaces[0]?.ipAddress).toEqual(expect.any(String));
52
53 const fetched = yield* compute.getVpnGateways({
54 project: created.gateway.project,
55 region: created.gateway.region,
56 vpnGateway: created.gateway.vpnGatewayName,
57 });
58 expect(fetched.name).toEqual(created.gateway.vpnGatewayName);
59 expect(fetched.description).toEqual("ha vpn");
60 expect(fetched.labels?.env).toEqual("test");
61 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
62 expect(fetched.network).toEqual(expect.stringContaining(`/networks/${DEFAULT_NETWORK}`));
63
64 const updated = yield* stack.deploy(
65 Effect.gen(function* () {
66 const gateway = yield* GCP.Compute.VpnGateway("Gateway", {
67 vpnGatewayName: created.gateway.vpnGatewayName,
68 region: "us-central1",
69 network: DEFAULT_NETWORK,
70 description: "ha vpn",
71 labels: { env: "prod", role: "vpn" },
72 });
73 return { gateway };
74 }),
75 );
76
77 expect(updated.gateway.vpnGatewayName).toEqual(created.gateway.vpnGatewayName);
78 expect(updated.gateway.vpnGatewayId).toEqual(created.gateway.vpnGatewayId);
79 expect(updated.gateway.labels).toMatchObject({
80 env: "prod",
81 role: "vpn",
82 });
83
84 const fetchedUpdated = yield* compute.getVpnGateways({
85 project: updated.gateway.project,
86 region: updated.gateway.region,
87 vpnGateway: updated.gateway.vpnGatewayName,
88 });
89 expect(fetchedUpdated.labels?.env).toEqual("prod");
90 expect(fetchedUpdated.labels?.role).toEqual("vpn");
91
92 yield* stack.destroy();
93
94 const gone = yield* waitUntilGone(
95 created.gateway.project,
96 created.gateway.region,
97 created.gateway.vpnGatewayName,
98 );
99 expect(gone).toEqual("gone");
100 }).pipe(logLevel),
101 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 180_000 },
102 );