@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 89 lines 3.16 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 certificatemanager from "@distilled.cloud/gcp/certificatemanager_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 certificatemanager.getProjectsLocationsCertificateMaps({ 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 a certificate map",
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.CertificateManager.CertificateMap("FrontendMap", {
33 location: "global",
34 description: "frontend map a",
35 labels: { env: "test" },
36 });
37 }),
38 );
39
40 expect(created.name).toContain("/certificateMaps/");
41 expect(created.certificateMapId).toEqual(expect.any(String));
42 expect(created.location).toEqual("global");
43 expect(created.description).toEqual("frontend map a");
44 expect(created.labels).toMatchObject({ env: "test" });
45 expect(created.gclbTargets).toEqual([]);
46 expect(created.createTime).toEqual(expect.any(String));
47
48 const fetched = yield* certificatemanager.getProjectsLocationsCertificateMaps({
49 name: created.name,
50 });
51 expect(fetched.name).toEqual(created.name);
52 expect(fetched.labels?.env).toEqual("test");
53 expect(fetched.description).toEqual("frontend map a");
54 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
55 true,
56 );
57
58 const updated = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.CertificateManager.CertificateMap("FrontendMap", {
61 certificateMapId: created.certificateMapId,
62 location: "global",
63 description: "frontend map b",
64 labels: { env: "prod", role: "tls" },
65 });
66 }),
67 );
68
69 expect(updated.name).toEqual(created.name);
70 expect(updated.description).toEqual("frontend map b");
71 expect(updated.labels).toMatchObject({ env: "prod", role: "tls" });
72
73 const refetched = yield* certificatemanager.getProjectsLocationsCertificateMaps({
74 name: created.name,
75 });
76 expect(refetched.description).toEqual("frontend map b");
77 expect(refetched.labels?.env).toEqual("prod");
78 expect(refetched.labels?.role).toEqual("tls");
79
80 yield* stack.destroy();
81
82 const gone = yield* waitUntilGone(created.name);
83 expect(gone).toEqual("gone");
84 }).pipe(logLevel),
85 {
86 tags: ["provider:gcp", "provider:gcp:certificatemanager", "live"],
87 timeout: 90_000,
88 },
89 );