@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 149 lines 5.21 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 firebasedataconnect from "@distilled.cloud/gcp/firebasedataconnect_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import {
8 connectorSource,
9 location,
10 logLevel,
11 missingConnector,
12 currentProject,
13 schemaSource,
14 unlinkedDatasources,
15 } from "./common.ts";
16
17 const { test } = Test.make({ providers: GCP.providers() });
18
19 const waitUntilGone = (name: string) =>
20 firebasedataconnect.getProjectsLocationsServicesConnectors({ name }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("3 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "getProjectsLocationsServicesConnectors on a missing connector fails with a typed tag",
32 (stack) =>
33 Effect.gen(function* () {
34 const project = yield* currentProject;
35
36 yield* stack.destroy();
37
38 const missing = yield* missingConnector();
39 const error = yield* Effect.flip(
40 firebasedataconnect.getProjectsLocationsServicesConnectors({
41 name: missing,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45
46 const page = yield* firebasedataconnect.listProjectsLocationsServicesConnectors({
47 parent: `projects/${project}/locations/${location}/services/-`,
48 pageSize: 10,
49 });
50 expect((page.connectors ?? []).map((item) => item.name)).not.toContain(missing);
51
52 yield* stack.destroy();
53 }).pipe(logLevel),
54 {
55 tags: ["provider:gcp", "provider:gcp:firebasedataconnect", "live"],
56 timeout: 90_000,
57 },
58 );
59
60 test.provider(
61 "create, update, and delete a Data Connect connector",
62 (stack) =>
63 Effect.gen(function* () {
64 yield* stack.destroy();
65
66 const created = yield* stack.deploy(
67 Effect.gen(function* () {
68 const service = yield* GCP.FirebaseDataConnect.Service("App", {
69 displayName: "alchemy-test-connector-svc",
70 labels: { env: "test" },
71 });
72 const schema = yield* GCP.FirebaseDataConnect.ServicesSchema("Main", {
73 service: service.name,
74 source: schemaSource(),
75 datasources: unlinkedDatasources,
76 labels: { env: "test" },
77 });
78 const connector = yield* GCP.FirebaseDataConnect.ServicesConnector("Queries", {
79 service: schema.service,
80 source: connectorSource,
81 displayName: "alchemy-test-connector",
82 labels: { env: "test" },
83 });
84 return { service, schema, connector };
85 }),
86 );
87
88 expect(created.connector.name).toContain("/connectors/");
89 expect(created.connector.connectorId).toEqual(expect.any(String));
90 expect(created.connector.location).toEqual(location);
91 expect(created.connector.displayName).toEqual("alchemy-test-connector");
92 expect(created.connector.labels).toMatchObject({ env: "test" });
93 expect(created.connector.service).toEqual(created.service.name);
94 expect(created.connector.reconciling).toEqual(false);
95
96 const fetched = yield* firebasedataconnect.getProjectsLocationsServicesConnectors({
97 name: created.connector.name,
98 });
99 expect(fetched.name).toEqual(created.connector.name);
100 expect(fetched.displayName).toEqual("alchemy-test-connector");
101 expect(fetched.labels?.env).toEqual("test");
102
103 const updated = yield* stack.deploy(
104 Effect.gen(function* () {
105 const service = yield* GCP.FirebaseDataConnect.Service("App", {
106 serviceId: created.service.serviceId,
107 displayName: "alchemy-prod-connector-svc",
108 labels: { env: "prod" },
109 });
110 const schema = yield* GCP.FirebaseDataConnect.ServicesSchema("Main", {
111 service: service.name,
112 source: schemaSource(),
113 datasources: unlinkedDatasources,
114 labels: { env: "prod" },
115 });
116 const connector = yield* GCP.FirebaseDataConnect.ServicesConnector("Queries", {
117 service: schema.service,
118 connectorId: created.connector.connectorId,
119 source: connectorSource,
120 displayName: "alchemy-prod-connector",
121 labels: { env: "prod", role: "query" },
122 });
123 return { service, schema, connector };
124 }),
125 );
126
127 expect(updated.connector.name).toEqual(created.connector.name);
128 expect(updated.connector.displayName).toEqual("alchemy-prod-connector");
129 expect(updated.connector.labels).toMatchObject({
130 env: "prod",
131 role: "query",
132 });
133
134 const refetched = yield* firebasedataconnect.getProjectsLocationsServicesConnectors({
135 name: created.connector.name,
136 });
137 expect(refetched.displayName).toEqual("alchemy-prod-connector");
138 expect(refetched.labels?.env).toEqual("prod");
139
140 yield* stack.destroy();
141
142 const gone = yield* waitUntilGone(created.connector.name);
143 expect(gone).toEqual("gone");
144 }).pipe(logLevel),
145 {
146 tags: ["provider:gcp", "provider:gcp:firebasedataconnect", "live"],
147 timeout: 120_000,
148 },
149 );