1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as vmwareengine from "@distilled.cloud/gcp/vmwareengine_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// Private clouds need VMware Engine node quota and bill thousands of dollars
18// a month; set GCP_TEST_VMWAREENGINE=1 on an entitled project to opt in.
19const runLifecycle = !!process.env.GCP_TEST_VMWAREENGINE && !process.env.FAST;
20
21const waitUntilGone = (name: string) =>
22 vmwareengine.getProjectsLocationsVmwareEngineNetworks({ name }).pipe(
23 Effect.as("found" as const),
24 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
25 Effect.repeat({
26 schedule: Schedule.spaced("2 seconds"),
27 until: (status) => status === "gone",
28 times: 10,
29 }),
30 );
31
32test.provider(
33 "getProjectsLocationsVmwareEngineNetworks on a missing network fails with a typed tag",
34 (stack) =>
35 Effect.gen(function* () {
36 const { project } = yield* GcpEnvironment.current;
37
38 yield* stack.destroy();
39
40 const error = yield* Effect.flip(
41 vmwareengine.getProjectsLocationsVmwareEngineNetworks({
42 name: `projects/${project}/locations/global/vmwareEngineNetworks/alchemy-ven-missing`,
43 }),
44 );
45 expect(error._tag).toEqual("NotFound");
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
51 timeout: 90_000,
52 },
53);
54
55test.provider.skipIf(!runLifecycle)(
56 "create, update, and delete a vmware engine network",
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.VMwareEngine.VmwareEngineNetwork("Ven", {
64 type: "STANDARD",
65 description: "alchemy-test-ven",
66 });
67 }),
68 );
69
70 expect(created.name).toContain("/vmwareEngineNetworks/");
71 expect(created.name).toContain("/locations/global/");
72 expect(created.vmwareEngineNetworkId).toEqual(expect.any(String));
73 expect(created.location).toEqual("global");
74 expect(created.type).toEqual("STANDARD");
75 expect(created.description).toEqual("alchemy-test-ven");
76 expect(created.state).toEqual("ACTIVE");
77 expect(created.createTime).toEqual(expect.any(String));
78
79 const fetched =
80 yield* vmwareengine.getProjectsLocationsVmwareEngineNetworks({
81 name: created.name,
82 });
83 expect(fetched.name).toEqual(created.name);
84 expect(fetched.type).toEqual("STANDARD");
85 expect(fetched.description).toContain("alchemy-id=");
86 expect(fetched.description).toContain("alchemy-test-ven");
87
88 const updated = yield* stack.deploy(
89 Effect.gen(function* () {
90 return yield* GCP.VMwareEngine.VmwareEngineNetwork("Ven", {
91 vmwareEngineNetworkId: created.vmwareEngineNetworkId,
92 location: "global",
93 type: "STANDARD",
94 description: "alchemy-prod-ven",
95 });
96 }),
97 );
98
99 expect(updated.name).toEqual(created.name);
100 expect(updated.uid).toEqual(created.uid);
101 expect(updated.description).toEqual("alchemy-prod-ven");
102
103 const refetched =
104 yield* vmwareengine.getProjectsLocationsVmwareEngineNetworks({
105 name: created.name,
106 });
107 expect(refetched.description).toContain("alchemy-prod-ven");
108 expect(refetched.description).toContain("alchemy-id=");
109
110 yield* stack.destroy();
111
112 const gone = yield* waitUntilGone(created.name);
113 expect(gone).toEqual("gone");
114 }).pipe(logLevel),
115 {
116 tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"],
117 timeout: 120_000,
118 },
119);