1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as compute from "@distilled.cloud/gcp/compute_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
17const runLifecycle =
18 !!process.env.GCP_TEST_COMPUTE_INTERCONNECT && !process.env.FAST;
19
20const waitUntilGone = (interconnectGroup: string) =>
21 GcpEnvironment.current.pipe(
22 Effect.flatMap(({ project }) =>
23 compute.getInterconnectGroups({ project, interconnectGroup }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 ),
32 ),
33 );
34
35test.provider(
36 "getInterconnectGroups on a missing group fails with NotFound",
37 (stack) =>
38 Effect.gen(function* () {
39 const { project } = yield* GcpEnvironment.current;
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 compute.getInterconnectGroups({
44 project,
45 interconnectGroup: "alchemy-missing-ixg",
46 }),
47 );
48 expect(error._tag).toBe("NotFound");
49
50 yield* stack.destroy();
51 }).pipe(logLevel),
52 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
53);
54
55test.provider.skipIf(!runLifecycle)(
56 "create, update, and delete an interconnect group",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* GCP.Compute.InterconnectGroup("Bundle", {
64 description: "dev interconnects",
65 intent: { topologyCapability: "NO_SLA" },
66 });
67 }),
68 );
69
70 expect(created.interconnectGroupName).toEqual(expect.any(String));
71 expect(created.description).toEqual("dev interconnects");
72
73 const fetched = yield* compute.getInterconnectGroups({
74 project: created.project,
75 interconnectGroup: created.interconnectGroupName,
76 });
77 expect(fetched.name).toEqual(created.interconnectGroupName);
78 expect(fetched.description).toContain("[alchemy ");
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 return yield* GCP.Compute.InterconnectGroup("Bundle", {
83 interconnectGroupName: created.interconnectGroupName,
84 description: "updated interconnects",
85 intent: { topologyCapability: "NO_SLA" },
86 });
87 }),
88 );
89 expect(updated.description).toEqual("updated interconnects");
90
91 yield* stack.destroy();
92 const gone = yield* waitUntilGone(created.interconnectGroupName);
93 expect(gone).toEqual("gone");
94 }).pipe(logLevel),
95 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
96);