@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.34 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 bqdt from "@distilled.cloud/gcp/bigquerydatatransfer_v1";
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 LOCATION = "us-central1";
15
16 const waitUntilGone = (name: string) =>
17 bqdt.getProjectsLocationsTransferConfigs({ name }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("1 second"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 );
26
27 test.provider(
28 "getProjectsLocationsTransferConfigs on a missing config fails with NotFound",
29 (stack) =>
30 Effect.gen(function* () {
31 const { project } = yield* GcpEnvironment.current;
32 yield* stack.destroy();
33
34 const error = yield* Effect.flip(
35 bqdt.getProjectsLocationsTransferConfigs({
36 name: `projects/${project}/locations/${LOCATION}/transferConfigs/00000000-0000-0000-0000-000000000000`,
37 }),
38 );
39 expect(error._tag).toBe("NotFound");
40
41 yield* stack.destroy();
42 }).pipe(logLevel),
43 {
44 tags: ["provider:gcp", "provider:gcp:bigquerydatatransfer", "live"],
45 timeout: 90_000,
46 },
47 );
48
49 test.provider(
50 "create, update, and delete a transfer config",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 const dataset = yield* GCP.BigQuery.Dataset("Analytics", {
58 location: "US-CENTRAL1",
59 forceDestroy: true,
60 });
61 return yield* GCP.BigQueryDataTransfer.TransferConfig("Nightly", {
62 location: "us-central1",
63 dataSourceId: "scheduled_query",
64 destinationDatasetId: dataset.datasetId,
65 displayName: "nightly",
66 schedule: "every 24 hours",
67 scheduleOptions: { disableAutoScheduling: true },
68 params: {
69 query: "SELECT 1 AS n",
70 destination_table_name_template: "nightly",
71 write_disposition: "WRITE_TRUNCATE",
72 },
73 });
74 }),
75 );
76
77 expect(created.name).toContain("/transferConfigs/");
78 expect(created.transferConfigId).toEqual(expect.any(String));
79 expect(created.location).toEqual("us-central1");
80 expect(created.dataSourceId).toEqual("scheduled_query");
81 expect(created.displayName).toEqual("nightly");
82 expect(created.disabled).toEqual(false);
83 expect(created.scheduleOptions?.disableAutoScheduling).toEqual(true);
84 expect(created.params).toMatchObject({
85 query: "SELECT 1 AS n",
86 destination_table_name_template: "nightly",
87 write_disposition: "WRITE_TRUNCATE",
88 });
89
90 const fetched = yield* bqdt.getProjectsLocationsTransferConfigs({
91 name: created.name,
92 });
93 expect(fetched.name).toEqual(created.name);
94 expect(fetched.dataSourceId).toEqual("scheduled_query");
95 expect(fetched.displayName).toContain("alchemy-id=");
96 expect(fetched.displayName).toContain("nightly");
97 expect(fetched.scheduleOptions?.disableAutoScheduling).toEqual(true);
98 expect(fetched.params).toMatchObject({
99 query: "SELECT 1 AS n",
100 destination_table_name_template: "nightly",
101 });
102
103 const updated = yield* stack.deploy(
104 Effect.gen(function* () {
105 const dataset = yield* GCP.BigQuery.Dataset("Analytics", {
106 location: "US-CENTRAL1",
107 forceDestroy: true,
108 });
109 return yield* GCP.BigQueryDataTransfer.TransferConfig("Nightly", {
110 location: "us-central1",
111 dataSourceId: "scheduled_query",
112 destinationDatasetId: dataset.datasetId,
113 displayName: "nightly v2",
114 schedule: "every 12 hours",
115 scheduleOptions: { disableAutoScheduling: true },
116 disabled: true,
117 params: {
118 query: "SELECT 2 AS n",
119 destination_table_name_template: "nightly",
120 write_disposition: "WRITE_TRUNCATE",
121 },
122 });
123 }),
124 );
125
126 expect(updated.name).toEqual(created.name);
127 expect(updated.transferConfigId).toEqual(created.transferConfigId);
128 expect(updated.displayName).toEqual("nightly v2");
129 expect(updated.disabled).toEqual(true);
130 expect(updated.scheduleOptions?.disableAutoScheduling).toEqual(true);
131 expect(updated.params).toMatchObject({ query: "SELECT 2 AS n" });
132
133 const fetchedUpdate = yield* bqdt.getProjectsLocationsTransferConfigs({
134 name: updated.name,
135 });
136 expect(fetchedUpdate.displayName).toContain("nightly v2");
137 expect(fetchedUpdate.disabled).toEqual(true);
138 expect(fetchedUpdate.params).toMatchObject({ query: "SELECT 2 AS n" });
139
140 yield* stack.destroy();
141
142 const gone = yield* waitUntilGone(updated.name);
143 expect(gone).toEqual("gone");
144 }).pipe(logLevel),
145 {
146 tags: ["provider:gcp", "provider:gcp:bigquerydatatransfer", "live"],
147 timeout: 120_000,
148 },
149 );