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