@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 124 lines 5.02 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 networkconnectivity from "@distilled.cloud/gcp/networkconnectivity_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 = (name: string) =>
15 networkconnectivity.getProjectsLocationsGlobalPolicyBasedRoutes({ name }).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, replace, and delete a policy-based route",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const created = yield* stack.deploy(
32 Effect.gen(function* () {
33 const route = yield* GCP.NetworkConnectivity.PolicyBasedRoute("Skip", {
34 network: DEFAULT_NETWORK,
35 filter: {
36 protocolVersion: "IPV4",
37 ipProtocol: "TCP",
38 srcRange: "10.0.0.0/8",
39 destRange: "192.0.2.0/24",
40 },
41 nextHopOtherRoutes: "DEFAULT_ROUTING",
42 virtualMachine: { tags: ["alchemy-pbr"] },
43 description: "pbr a",
44 labels: { env: "test" },
45 });
46 return { route };
47 }),
48 );
49
50 expect(created.route.name).toContain("/policyBasedRoutes/");
51 expect(created.route.name).toContain("/locations/global/");
52 expect(created.route.policyBasedRouteId).toEqual(expect.any(String));
53 expect(created.route.location).toEqual("global");
54 expect(created.route.network).toContain(`networks/${DEFAULT_NETWORK}`);
55 expect(created.route.filter.protocolVersion).toEqual("IPV4");
56 expect(created.route.filter.ipProtocol?.toUpperCase()).toEqual("TCP");
57 expect(created.route.filter.srcRange).toEqual("10.0.0.0/8");
58 expect(created.route.filter.destRange).toEqual("192.0.2.0/24");
59 expect(created.route.nextHopOtherRoutes).toEqual("DEFAULT_ROUTING");
60 expect(created.route.virtualMachine?.tags).toEqual(["alchemy-pbr"]);
61 expect(created.route.priority).toEqual(1000);
62 expect(created.route.description).toEqual("pbr a");
63 expect(created.route.labels).toMatchObject({ env: "test" });
64 expect(created.route.createTime).toEqual(expect.any(String));
65
66 const fetched = yield* networkconnectivity.getProjectsLocationsGlobalPolicyBasedRoutes({
67 name: created.route.name,
68 });
69 expect(fetched.name).toEqual(created.route.name);
70 expect(fetched.filter?.destRange).toEqual("192.0.2.0/24");
71 expect(fetched.nextHopOtherRoutes).toEqual("DEFAULT_ROUTING");
72 expect(fetched.virtualMachine?.tags).toEqual(["alchemy-pbr"]);
73 expect(fetched.description).toEqual("pbr a");
74 expect(fetched.labels?.env).toEqual("test");
75 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
76 true,
77 );
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 const route = yield* GCP.NetworkConnectivity.PolicyBasedRoute("Skip", {
82 policyBasedRouteId: created.route.policyBasedRouteId,
83 network: DEFAULT_NETWORK,
84 filter: {
85 protocolVersion: "IPV4",
86 ipProtocol: "TCP",
87 srcRange: "10.0.0.0/8",
88 destRange: "198.51.100.0/24",
89 },
90 nextHopOtherRoutes: "DEFAULT_ROUTING",
91 virtualMachine: { tags: ["alchemy-pbr"] },
92 priority: 900,
93 description: "pbr b",
94 labels: { env: "prod", role: "pbr" },
95 });
96 return { route };
97 }),
98 );
99
100 expect(updated.route.policyBasedRouteId).toEqual(created.route.policyBasedRouteId);
101 expect(updated.route.filter.destRange).toEqual("198.51.100.0/24");
102 expect(updated.route.priority).toEqual(900);
103 expect(updated.route.description).toEqual("pbr b");
104 expect(updated.route.labels).toMatchObject({ env: "prod", role: "pbr" });
105
106 const refetched = yield* networkconnectivity.getProjectsLocationsGlobalPolicyBasedRoutes({
107 name: updated.route.name,
108 });
109 expect(refetched.filter?.destRange).toEqual("198.51.100.0/24");
110 expect(refetched.priority).toEqual(900);
111 expect(refetched.description).toEqual("pbr b");
112 expect(refetched.labels?.env).toEqual("prod");
113 expect(refetched.labels?.role).toEqual("pbr");
114
115 yield* stack.destroy();
116
117 const gone = yield* waitUntilGone(created.route.name);
118 expect(gone).toEqual("gone");
119 }).pipe(logLevel),
120 {
121 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
122 timeout: 600_000,
123 },
124 );