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.getProjectsLocationsExascaleDbStorageVaults({ 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 "getProjectsLocationsExascaleDbStorageVaults 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.getProjectsLocationsExascaleDbStorageVaults({
43 name: `projects/${project}/locations/us-central1/exascaleDbStorageVaults/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 an exascale db storage vault",
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 return yield* GCP.OracleDatabase.ExascaleDbStorageVault("Vault", {
67 location: "us-central1",
68 displayName: "alchemyvault",
69 totalSizeGbs: 300,
70 labels: { env: "test" },
71 });
72 }),
73 );
74
75 expect(created.name).toContain("/exascaleDbStorageVaults/");
76 expect(created.exascaleDbStorageVaultId).toEqual(expect.any(String));
77 expect(created.labels).toMatchObject({ env: "test" });
78
79 const fetched = yield* oracle.getProjectsLocationsExascaleDbStorageVaults(
80 {
81 name: created.name,
82 },
83 );
84 expect(fetched.name).toEqual(created.name);
85
86 yield* stack.destroy();
87
88 const gone = yield* waitUntilGone(created.name);
89 expect(gone).toEqual("gone");
90 }).pipe(logLevel),
91 {
92 tags: ["provider:gcp", "provider:gcp:oracledatabase", "live"],
93 timeout: 120_000,
94 },
95);