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;
21
22const waitUntilGone = (name: string) =>
23 oracle.getProjectsLocationsGoldengateConnectionAssignments({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("2 seconds"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33test.provider.skipIf(runLifecycle)(
34 "getProjectsLocationsGoldengateConnectionAssignments without Oracle Database enabled fails with ServiceDisabled",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38
39 yield* stack.destroy();
40
41 const error = yield* Effect.flip(
42 oracle.getProjectsLocationsGoldengateConnectionAssignments({
43 name: `projects/${project}/locations/us-central1/goldengateConnectionAssignments/alchemy-oracle-missing`,
44 }),
45 );
46 expect(error._tag).toEqual("ServiceDisabled");
47
48 yield* stack.destroy();
49 }).pipe(logLevel),
50 {
51 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
52 timeout: 90_000,
53 },
54);
55
56test.provider.skipIf(!runLifecycle)(
57 "create, update, and delete a goldengate connection assignment",
58 (stack) =>
59 Effect.gen(function* () {
60 const { project } = yield* GcpEnvironment.current;
61
62 yield* stack.destroy();
63
64 const created = yield* stack.deploy(
65 Effect.gen(function* () {
66 const connection = yield* GCP.OracleDatabase.GoldengateConnection(
67 "Src",
68 {
69 connectionType: "GENERIC",
70 displayName: "alchemy-gg-src",
71 properties: {
72 genericConnectionProperties: {
73 host: "db.example.com",
74 technologyType: "GENERIC",
75 },
76 },
77 },
78 );
79 return yield* GCP.OracleDatabase.GoldengateConnectionAssignment(
80 "Assign",
81 {
82 location: "us-central1",
83 displayName: "alchemy-gg-assign",
84 goldengateConnection: connection.name,
85 goldengateDeployment: `projects/${project}/locations/us-central1/goldengateDeployments/missing`,
86 labels: { env: "test" },
87 },
88 );
89 }),
90 );
91
92 expect(created.name).toContain("/goldengateConnectionAssignments/");
93 expect(created.goldengateConnectionAssignmentId).toEqual(
94 expect.any(String),
95 );
96 expect(created.labels).toMatchObject({ env: "test" });
97
98 const fetched =
99 yield* oracle.getProjectsLocationsGoldengateConnectionAssignments({
100 name: created.name,
101 });
102 expect(fetched.name).toEqual(created.name);
103
104 yield* stack.destroy();
105
106 const gone = yield* waitUntilGone(created.name);
107 expect(gone).toEqual("gone");
108 }).pipe(logLevel),
109 {
110 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
111 timeout: 120_000,
112 },
113);