@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 116 lines 4.25 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 compute from "@distilled.cloud/gcp/compute_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { CERT_A_PEM, CERT_B_PEM, KEY_A_PEM, KEY_B_PEM } from "./fixtures/https-proxy-cert.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const region = "us-central1";
16
17 const waitUntilGone = (sslCertificateName: string) =>
18 GcpEnvironment.current.pipe(
19 Effect.flatMap(({ project }) =>
20 compute
21 .getRegionSslCertificates({
22 project,
23 region,
24 sslCertificate: sslCertificateName,
25 })
26 .pipe(
27 Effect.as("found" as const),
28 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
29 Effect.repeat({
30 schedule: Schedule.spaced("1 second"),
31 until: (status) => status === "gone",
32 times: 10,
33 }),
34 ),
35 ),
36 );
37
38 test.provider(
39 "create, replace, and delete a regional ssl certificate",
40 (stack) =>
41 Effect.gen(function* () {
42 const { project } = yield* GcpEnvironment.current;
43 yield* stack.destroy();
44
45 const created = yield* stack.deploy(
46 Effect.gen(function* () {
47 return yield* GCP.Compute.RegionSslCertificate("FrontendTls", {
48 region,
49 description: "frontend tls a",
50 certificate: CERT_A_PEM,
51 privateKey: KEY_A_PEM,
52 });
53 }),
54 );
55
56 expect(created.sslCertificateName).toEqual(expect.any(String));
57 expect(created.region).toEqual(region);
58 expect(created.type).toEqual("SELF_MANAGED");
59 expect(created.description).toEqual("frontend tls a");
60 expect(created.certificate).toContain("MIIDIDCCAgigAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWMw");
61 expect(created.expireTime).toEqual(expect.any(String));
62 expect(created.selfLink).toEqual(expect.any(String));
63
64 const fetched = yield* compute.getRegionSslCertificates({
65 project,
66 region,
67 sslCertificate: created.sslCertificateName,
68 });
69 expect(fetched.name).toEqual(created.sslCertificateName);
70 expect(fetched.type).toEqual("SELF_MANAGED");
71 expect(fetched.description).toContain("[alchemy ");
72 expect(fetched.description).toContain("frontend tls a");
73 expect(fetched.certificate).toContain("BEGIN CERTIFICATE");
74 expect(fetched.certificate).toContain("MIIDIDCCAgigAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWMw");
75
76 const listed = yield* compute.listRegionSslCertificates({
77 project,
78 region,
79 maxResults: 500,
80 });
81 expect((listed.items ?? []).some((cert) => cert.name === created.sslCertificateName)).toEqual(
82 true,
83 );
84
85 const updated = yield* stack.deploy(
86 Effect.gen(function* () {
87 return yield* GCP.Compute.RegionSslCertificate("FrontendTls", {
88 sslCertificateName: created.sslCertificateName,
89 region,
90 description: "frontend tls b",
91 certificate: CERT_B_PEM,
92 privateKey: KEY_B_PEM,
93 });
94 }),
95 );
96
97 expect(updated.sslCertificateName).toEqual(created.sslCertificateName);
98 expect(updated.description).toEqual("frontend tls b");
99 expect(updated.certificate).toContain("MIIDITCCAgmgAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWQw");
100 expect(updated.certificate).not.toContain("MIIDIDCCAgigAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWMw");
101
102 const refetched = yield* compute.getRegionSslCertificates({
103 project,
104 region,
105 sslCertificate: updated.sslCertificateName,
106 });
107 expect(refetched.description).toContain("frontend tls b");
108 expect(refetched.certificate).toContain("MIIDITCCAgmgAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWQw");
109
110 yield* stack.destroy();
111
112 const gone = yield* waitUntilGone(created.sslCertificateName);
113 expect(gone).toEqual("gone");
114 }).pipe(logLevel),
115 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
116 );