@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 127 lines 4.72 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as networkconnectivity from "@distilled.cloud/gcp/networkconnectivity_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const runLifecycle = !process.env.FAST;
15
16 const waitUntilGone = (name: string) =>
17 networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigsDestinations({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsMulticloudDataTransferConfigsDestinations on a missing destination fails with a typed tag",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigsDestinations({
36 name: `projects/${project}/locations/us-central1/multicloudDataTransferConfigs/alchemy-missing/destinations/alchemy-missing`,
37 }),
38 );
39 expect(error._tag).toEqual("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
45 timeout: 90_000,
46 },
47 );
48
49 test.provider.skipIf(!runLifecycle)(
50 "create, update, and delete a multicloud data transfer destination",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 const config = yield* GCP.NetworkConnectivity.MulticloudDataTransferConfig("Dte", {
58 location: "europe-west3",
59 description: "dte parent",
60 services: { "cloud-storage": {} },
61 });
62 const destination =
63 yield* GCP.NetworkConnectivity.MulticloudDataTransferConfigsDestination("OnPrem", {
64 parent: config.name,
65 ipPrefix: "203.0.113.0/24",
66 endpoints: [{ asn: "16509", csp: "AWS" }],
67 description: "dest a",
68 labels: { env: "test" },
69 });
70 return { config, destination };
71 }),
72 );
73
74 expect(created.destination.name).toContain("/destinations/");
75 expect(created.destination.parent).toEqual(created.config.name);
76 expect(created.destination.ipPrefix).toEqual("203.0.113.0/24");
77 expect(created.destination.labels).toMatchObject({ env: "test" });
78
79 const fetched =
80 yield* networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigsDestinations({
81 name: created.destination.name,
82 });
83 expect(fetched.name).toEqual(created.destination.name);
84 expect(fetched.ipPrefix).toEqual("203.0.113.0/24");
85 expect(fetched.labels?.env).toEqual("test");
86 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
87 true,
88 );
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 const config = yield* GCP.NetworkConnectivity.MulticloudDataTransferConfig("Dte", {
93 multicloudDataTransferConfigId: created.config.multicloudDataTransferConfigId,
94 location: created.config.location,
95 description: "dte parent",
96 services: { "cloud-storage": {} },
97 });
98 const destination =
99 yield* GCP.NetworkConnectivity.MulticloudDataTransferConfigsDestination("OnPrem", {
100 parent: config.name,
101 destinationId: created.destination.destinationId,
102 ipPrefix: "203.0.113.0/24",
103 endpoints: [{ asn: "16509", csp: "AWS" }],
104 description: "dest b",
105 labels: { env: "prod", role: "dte" },
106 });
107 return { config, destination };
108 }),
109 );
110
111 expect(updated.destination.name).toEqual(created.destination.name);
112 expect(updated.destination.description).toEqual("dest b");
113 expect(updated.destination.labels).toMatchObject({
114 env: "prod",
115 role: "dte",
116 });
117
118 yield* stack.destroy();
119
120 const gone = yield* waitUntilGone(created.destination.name);
121 expect(gone).toEqual("gone");
122 }).pipe(logLevel),
123 {
124 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
125 timeout: 180_000,
126 },
127 );