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