@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 96 lines 3.43 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.getProjectsLocationsAuthorizationPolicies({ 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 authorization policy",
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.AuthorizationPolicy("Allow", {
33 action: "ALLOW",
34 description: "authz policy a",
35 labels: { env: "test" },
36 });
37 }),
38 );
39
40 expect(created.name).toContain("/authorizationPolicies/");
41 expect(created.name).toContain("/locations/global/");
42 expect(created.authorizationPolicyId).toEqual(expect.any(String));
43 expect(created.location).toEqual("global");
44 expect(created.action).toEqual("ALLOW");
45 expect(created.description).toEqual("authz policy a");
46 expect(created.labels).toMatchObject({ env: "test" });
47 expect(created.createTime).toEqual(expect.any(String));
48
49 const fetched = yield* networksecurity.getProjectsLocationsAuthorizationPolicies({
50 name: created.name,
51 });
52 expect(fetched.name).toEqual(created.name);
53 expect(fetched.labels?.env).toEqual("test");
54 expect(fetched.action).toEqual("ALLOW");
55 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
56 true,
57 );
58
59 const updated = yield* stack.deploy(
60 Effect.gen(function* () {
61 return yield* GCP.NetworkSecurity.AuthorizationPolicy("Allow", {
62 authorizationPolicyId: created.authorizationPolicyId,
63 action: "ALLOW",
64 rules: [
65 {
66 destinations: [{ hosts: ["api.example.com"], ports: [443] }],
67 },
68 ],
69 description: "authz policy b",
70 labels: { env: "prod", role: "authz" },
71 });
72 }),
73 );
74
75 expect(updated.name).toEqual(created.name);
76 expect(updated.description).toEqual("authz policy b");
77 expect(updated.rules.length).toBeGreaterThan(0);
78 expect(updated.labels).toMatchObject({ env: "prod", role: "authz" });
79
80 const refetched = yield* networksecurity.getProjectsLocationsAuthorizationPolicies({
81 name: created.name,
82 });
83 expect(refetched.description).toEqual("authz policy b");
84 expect(refetched.labels?.env).toEqual("prod");
85 expect(refetched.rules?.length).toBeGreaterThan(0);
86
87 yield* stack.destroy();
88
89 const gone = yield* waitUntilGone(created.name);
90 expect(gone).toEqual("gone");
91 }).pipe(logLevel),
92 {
93 tags: ["provider:gcp", "provider:gcp:networksecurity", "live"],
94 timeout: 90_000,
95 },
96 );