@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 151 lines 5.31 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 oracle from "@distilled.cloud/gcp/oracledatabase_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 // Oracle Database@Google Cloud is not enabled in the test project
15 // (ServiceDisabled) and needs an Oracle Cloud subscription. Set
16 // GCP_TEST_ORACLE=1 in a project that has one.
17 const runLifecycle = !!process.env.GCP_TEST_ORACLE && !process.env.FAST;
18 const location = "us-central1";
19
20 const waitUntilGone = (name: string) =>
21 oracle.getProjectsLocationsGoldengateDeployments({ name }).pipe(
22 Effect.as("found" as const),
23 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (status) => status === "gone",
27 times: 10,
28 }),
29 );
30
31 test.provider.skipIf(runLifecycle)(
32 "getProjectsLocationsGoldengateDeployments without Oracle Database enabled fails with ServiceDisabled",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 oracle.getProjectsLocationsGoldengateDeployments({
41 name: `projects/${project}/locations/${location}/goldengateDeployments/alchemy-gg-missing`,
42 }),
43 );
44 expect(error._tag).toEqual("ServiceDisabled");
45
46 yield* stack.destroy();
47 }).pipe(logLevel),
48 {
49 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
50 timeout: 90_000,
51 },
52 );
53
54 test.provider.skipIf(!runLifecycle)(
55 "create, update, and delete a goldengate deployment",
56 (stack) =>
57 Effect.gen(function* () {
58 const { project } = yield* GcpEnvironment.current;
59
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 const net = yield* GCP.OracleDatabase.OdbNetwork("OracleNet", {
65 location,
66 network: "default",
67 labels: { env: "test" },
68 });
69 const subnet = yield* GCP.OracleDatabase.OdbNetworksOdbSubnet("Client", {
70 odbNetwork: net.name,
71 location,
72 cidrRange: "10.250.0.0/27",
73 purpose: "CLIENT_SUBNET",
74 });
75 const gg = yield* GCP.OracleDatabase.GoldengateDeployment("Replicat", {
76 location,
77 odbNetwork: net.name,
78 odbSubnet: subnet.name,
79 displayName: "alchemy-gg",
80 deploymentType: "DATABASE_ORACLE",
81 oggData: {
82 adminUsername: "oggadmin",
83 deployment: "oggdeploy",
84 adminPassword: "AlchemyTest1!",
85 },
86 labels: { env: "test" },
87 });
88 return { net, subnet, gg };
89 }),
90 );
91
92 expect(created.gg.name).toContain("/goldengateDeployments/");
93 expect(created.gg.goldengateDeploymentId).toEqual(expect.any(String));
94 expect(created.gg.location).toEqual(location);
95 expect(created.gg.odbSubnet).toEqual(created.subnet.name);
96 expect(created.gg.displayName).toEqual("alchemy-gg");
97 expect(created.gg.labels).toMatchObject({ env: "test" });
98
99 const fetched = yield* oracle.getProjectsLocationsGoldengateDeployments({
100 name: created.gg.name,
101 });
102 expect(fetched.name).toEqual(created.gg.name);
103 expect(fetched.labels?.env).toEqual("test");
104 expect(fetched.displayName).toEqual("alchemy-gg");
105
106 const updated = yield* stack.deploy(
107 Effect.gen(function* () {
108 const net = yield* GCP.OracleDatabase.OdbNetwork("OracleNet", {
109 odbNetworkId: created.net.odbNetworkId,
110 location,
111 network: "default",
112 labels: { env: "prod" },
113 });
114 const subnet = yield* GCP.OracleDatabase.OdbNetworksOdbSubnet("Client", {
115 odbNetwork: net.name,
116 odbSubnetId: created.subnet.odbSubnetId,
117 location,
118 cidrRange: "10.250.0.0/27",
119 purpose: "CLIENT_SUBNET",
120 });
121 const gg = yield* GCP.OracleDatabase.GoldengateDeployment("Replicat", {
122 goldengateDeploymentId: created.gg.goldengateDeploymentId,
123 location,
124 odbNetwork: net.name,
125 odbSubnet: subnet.name,
126 displayName: "alchemy-gg",
127 deploymentType: "DATABASE_ORACLE",
128 oggData: {
129 adminUsername: "oggadmin",
130 deployment: "oggdeploy",
131 adminPassword: "AlchemyTest1!",
132 },
133 labels: { env: "prod", role: "gg" },
134 });
135 return { net, subnet, gg };
136 }),
137 );
138
139 expect(updated.gg.name).toEqual(created.gg.name);
140 expect(updated.gg.goldengateDeploymentId).toEqual(created.gg.goldengateDeploymentId);
141
142 yield* stack.destroy();
143
144 const gone = yield* waitUntilGone(created.gg.name);
145 expect(gone).toEqual("gone");
146 }).pipe(logLevel),
147 {
148 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
149 timeout: 120_000,
150 },
151 );