@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 97 lines 3.48 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 networksecurity from "@distilled.cloud/gcp/networksecurity_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 networksecurity.getProjectsLocationsAddressGroups({ 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(
25 "create, update, and delete an address group",
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.NetworkSecurity.AddressGroup("Allowlist", {
33 type: "IPV4",
34 capacity: 100,
35 items: ["10.0.0.1"],
36 description: "address group a",
37 labels: { env: "test" },
38 });
39 }),
40 );
41
42 expect(created.name).toContain("/addressGroups/");
43 expect(created.name).toContain("/locations/global/");
44 expect(created.addressGroupId).toEqual(expect.any(String));
45 expect(created.location).toEqual("global");
46 expect(created.type).toEqual("IPV4");
47 expect(created.capacity).toEqual(100);
48 expect(created.items).toEqual(["10.0.0.1"]);
49 expect(created.description).toEqual("address group a");
50 expect(created.labels).toMatchObject({ env: "test" });
51 expect(created.createTime).toEqual(expect.any(String));
52
53 const fetched = yield* networksecurity.getProjectsLocationsAddressGroups({
54 name: created.name,
55 });
56 expect(fetched.name).toEqual(created.name);
57 expect(fetched.labels?.env).toEqual("test");
58 expect(fetched.items).toEqual(["10.0.0.1"]);
59 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
60 true,
61 );
62
63 const updated = yield* stack.deploy(
64 Effect.gen(function* () {
65 return yield* GCP.NetworkSecurity.AddressGroup("Allowlist", {
66 addressGroupId: created.addressGroupId,
67 type: "IPV4",
68 capacity: 100,
69 items: ["10.0.0.1", "10.1.0.0/24"],
70 description: "address group b",
71 labels: { env: "prod", role: "allowlist" },
72 });
73 }),
74 );
75
76 expect(updated.name).toEqual(created.name);
77 expect(updated.description).toEqual("address group b");
78 expect(updated.items.sort()).toEqual(["10.0.0.1", "10.1.0.0/24"].sort());
79 expect(updated.labels).toMatchObject({ env: "prod", role: "allowlist" });
80
81 const refetched = yield* networksecurity.getProjectsLocationsAddressGroups({
82 name: created.name,
83 });
84 expect(refetched.description).toEqual("address group b");
85 expect(refetched.labels?.env).toEqual("prod");
86 expect(refetched.labels?.role).toEqual("allowlist");
87
88 yield* stack.destroy();
89
90 const gone = yield* waitUntilGone(created.name);
91 expect(gone).toEqual("gone");
92 }).pipe(logLevel),
93 {
94 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
95 timeout: 90_000,
96 },
97 );