@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 147 lines 5.51 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 bigqueryconnection from "@distilled.cloud/gcp/bigqueryconnection_v1";
5 import { Action } from "alchemy/Action";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const waitUntilGone = (name: string) =>
15 bigqueryconnection.getProjectsLocationsConnections({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "create, update, replace, and delete a cloud resource connection",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const { connection: created, live } = yield* stack.deploy(
32 Effect.gen(function* () {
33 const connection = yield* GCP.BigQueryConnection.Connection("Gcs", {
34 location: "us-central1",
35 friendlyName: "gcs-test",
36 description: "cloud resource connection",
37 cloudResource: {},
38 });
39 const Probe = Action(
40 "Probe",
41 Effect.gen(function* () {
42 yield* connection.name;
43 const getConnection = yield* GCP.BigQueryConnection.GetConnection(connection);
44 return Effect.fn(function* () {
45 return yield* getConnection();
46 });
47 }),
48 );
49 return {
50 connection,
51 live: yield* Probe({}),
52 };
53 }),
54 );
55
56 expect(created.connectionId).toEqual(expect.any(String));
57 expect(created.name).toContain("/connections/");
58 expect(created.location).toEqual("us-central1");
59 expect(created.kind).toEqual("cloudResource");
60 expect(created.friendlyName).toEqual("gcs-test");
61 expect(created.description).toEqual("cloud resource connection");
62 expect(created.cloudResource).toEqual(expect.any(Object));
63 expect(created.serviceAccountId).toEqual(expect.any(String));
64 expect(live.name).toEqual(created.name);
65 expect(live.cloudResource).toEqual(expect.any(Object));
66
67 const fetched = yield* bigqueryconnection.getProjectsLocationsConnections({
68 name: created.name,
69 });
70 expect(fetched.name).toEqual(created.name);
71 expect(fetched.friendlyName).toEqual("gcs-test");
72 expect(fetched.description).toContain("alchemy-id=");
73 expect(fetched.description).toContain("cloud resource connection");
74 expect(fetched.cloudResource).toEqual(expect.any(Object));
75
76 const listed = yield* bigqueryconnection.listProjectsLocationsConnections({
77 parent: `projects/${created.project}/locations/${created.location}`,
78 pageSize: 100,
79 });
80 expect(
81 (listed.connections ?? []).some((connection) => connection.name === created.name),
82 ).toEqual(true);
83
84 const updated = yield* stack.deploy(
85 Effect.gen(function* () {
86 return yield* GCP.BigQueryConnection.Connection("Gcs", {
87 connectionId: created.connectionId,
88 location: "us-central1",
89 friendlyName: "gcs-prod",
90 description: "updated cloud resource",
91 cloudResource: {},
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.connectionId).toEqual(created.connectionId);
98 expect(updated.friendlyName).toEqual("gcs-prod");
99 expect(updated.description).toEqual("updated cloud resource");
100 expect(updated.kind).toEqual("cloudResource");
101 expect(updated.creationTime).toEqual(created.creationTime);
102
103 const fetchedUpdate = yield* bigqueryconnection.getProjectsLocationsConnections({
104 name: updated.name,
105 });
106 expect(fetchedUpdate.friendlyName).toEqual("gcs-prod");
107 expect(fetchedUpdate.description).toContain("updated cloud resource");
108
109 const last = created.connectionId.at(-1) ?? "a";
110 const nextConnectionId = `${created.connectionId.slice(0, -1)}${last === "z" ? "0" : "z"}`;
111
112 const replaced = yield* stack.deploy(
113 Effect.gen(function* () {
114 return yield* GCP.BigQueryConnection.Connection("Gcs", {
115 connectionId: nextConnectionId,
116 location: "us-central1",
117 friendlyName: "gcs-replaced",
118 description: "replaced connection",
119 cloudResource: {},
120 });
121 }),
122 );
123
124 expect(replaced.connectionId).not.toEqual(created.connectionId);
125 expect(replaced.connectionId).toEqual(nextConnectionId);
126 expect(replaced.friendlyName).toEqual("gcs-replaced");
127 expect(replaced.kind).toEqual("cloudResource");
128
129 const fetchedReplace = yield* bigqueryconnection.getProjectsLocationsConnections({
130 name: replaced.name,
131 });
132 expect(fetchedReplace.name).toEqual(replaced.name);
133 expect(fetchedReplace.friendlyName).toEqual("gcs-replaced");
134
135 const oldGone = yield* waitUntilGone(created.name);
136 expect(oldGone).toEqual("gone");
137
138 yield* stack.destroy();
139
140 const gone = yield* waitUntilGone(replaced.name);
141 expect(gone).toEqual("gone");
142 }).pipe(logLevel),
143 {
144 tags: ["provider:gcp", "provider:gcp:bigqueryconnection", "live"],
145 timeout: 90_000,
146 },
147 );