1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as vmmigration from "@distilled.cloud/gcp/vmmigration_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { logLevel, currentProject, waitUntilGone } from "./common.ts";
7
8const { test } = Test.make({ providers: GCP.providers() });
9
10test.provider(
11 "getProjectsLocationsGroups on a missing group fails with a typed tag",
12 (stack) =>
13 Effect.gen(function* () {
14 const project = yield* currentProject;
15 yield* stack.destroy();
16
17 const error = yield* Effect.flip(
18 vmmigration.getProjectsLocationsGroups({
19 name: `projects/${project}/locations/us-central1/groups/alchemy-missing-group`,
20 }),
21 );
22 expect(error._tag).toEqual("NotFound");
23
24 yield* stack.destroy();
25 }).pipe(logLevel),
26 {
27 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
28 timeout: 90_000,
29 },
30);
31
32test.provider(
33 "create, update, and delete a vm migration group",
34 (stack) =>
35 Effect.gen(function* () {
36 const project = yield* currentProject;
37 yield* stack.destroy();
38
39 const created = yield* stack.deploy(
40 Effect.gen(function* () {
41 return yield* GCP.VMMigration.Group("Workloads", {
42 location: "us-central1",
43 displayName: "workloads",
44 description: "production vms",
45 });
46 }),
47 );
48
49 expect(created.groupId).toEqual(expect.any(String));
50 expect(created.name).toEqual(
51 `projects/${project}/locations/us-central1/groups/${created.groupId}`,
52 );
53 expect(created.location).toEqual("us-central1");
54 expect(created.displayName).toEqual("workloads");
55 expect(created.description).toEqual("production vms");
56
57 const fetched = yield* vmmigration.getProjectsLocationsGroups({
58 name: created.name,
59 });
60 expect(fetched.name).toEqual(created.name);
61 expect(fetched.displayName).toEqual("workloads");
62 expect(fetched.description).toContain("alchemy-id=");
63 expect(fetched.description).toContain("production vms");
64
65 const updated = yield* stack.deploy(
66 Effect.gen(function* () {
67 return yield* GCP.VMMigration.Group("Workloads", {
68 groupId: created.groupId,
69 location: "us-central1",
70 displayName: "workloads-v2",
71 description: "production vms v2",
72 });
73 }),
74 );
75
76 expect(updated.name).toEqual(created.name);
77 expect(updated.displayName).toEqual("workloads-v2");
78 expect(updated.description).toEqual("production vms v2");
79
80 const fetchedUpdate = yield* vmmigration.getProjectsLocationsGroups({
81 name: updated.name,
82 });
83 expect(fetchedUpdate.displayName).toEqual("workloads-v2");
84 expect(fetchedUpdate.description).toContain("production vms v2");
85
86 yield* stack.destroy();
87 const gone = yield* waitUntilGone(
88 vmmigration.getProjectsLocationsGroups({ name: created.name }),
89 );
90 expect(gone).toEqual("gone");
91 }).pipe(logLevel),
92 {
93 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
94 timeout: 90_000,
95 },
96);