@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 94 lines 3.34 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
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 networkconnectivity.getProjectsLocationsGlobalHubs({ name }).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.skipIf(!!process.env.FAST)(
25 "create, update, and delete a hub",
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.NetworkConnectivity.Hub("Mesh", {
33 description: "ncc hub a",
34 labels: { env: "test" },
35 });
36 }),
37 );
38
39 expect(created.name).toContain("/hubs/");
40 expect(created.name).toContain("/locations/global/");
41 expect(created.hubId).toEqual(expect.any(String));
42 expect(created.location).toEqual("global");
43 expect(created.description).toEqual("ncc hub a");
44 expect(created.exportPsc).toEqual(false);
45 expect(created.labels).toMatchObject({ env: "test" });
46 expect(created.uniqueId).toEqual(expect.any(String));
47 expect(created.createTime).toEqual(expect.any(String));
48 expect(created.state).toEqual("ACTIVE");
49
50 const fetched = yield* networkconnectivity.getProjectsLocationsGlobalHubs({
51 name: created.name,
52 });
53 expect(fetched.name).toEqual(created.name);
54 expect(fetched.labels?.env).toEqual("test");
55 expect(fetched.description).toEqual("ncc hub a");
56 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
57 true,
58 );
59
60 const updated = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.NetworkConnectivity.Hub("Mesh", {
63 hubId: created.hubId,
64 description: "ncc hub b",
65 exportPsc: true,
66 labels: { env: "prod", role: "ncc" },
67 });
68 }),
69 );
70
71 expect(updated.name).toEqual(created.name);
72 expect(updated.uniqueId).toEqual(created.uniqueId);
73 expect(updated.description).toEqual("ncc hub b");
74 expect(updated.exportPsc).toEqual(true);
75 expect(updated.labels).toMatchObject({ env: "prod", role: "ncc" });
76
77 const refetched = yield* networkconnectivity.getProjectsLocationsGlobalHubs({
78 name: created.name,
79 });
80 expect(refetched.description).toEqual("ncc hub b");
81 expect(refetched.exportPsc).toEqual(true);
82 expect(refetched.labels?.env).toEqual("prod");
83 expect(refetched.labels?.role).toEqual("ncc");
84
85 yield* stack.destroy();
86
87 const gone = yield* waitUntilGone(created.name);
88 expect(gone).toEqual("gone");
89 }).pipe(logLevel),
90 {
91 tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"],
92 timeout: 120_000,
93 },
94 );