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 {
7 dummyAws,
8 logLevel,
9 currentProject,
10 runSourceLifecycle,
11 waitUntilGone,
12} from "./common.ts";
13
14const { test } = Test.make({ providers: GCP.providers() });
15
16test.provider(
17 "getProjectsLocationsSourcesMigratingVms on a missing vm fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 const project = yield* currentProject;
21 yield* stack.destroy();
22
23 const error = yield* Effect.flip(
24 vmmigration.getProjectsLocationsSourcesMigratingVms({
25 name: `projects/${project}/locations/us-central1/sources/alchemy-missing-source/migratingVms/alchemy-missing-vm`,
26 }),
27 );
28 expect(error._tag).toEqual("NotFound");
29
30 yield* stack.destroy();
31 }).pipe(logLevel),
32 {
33 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
34 timeout: 90_000,
35 },
36);
37
38test.provider.skipIf(!runSourceLifecycle)(
39 "create, update, and delete a vm migration migrating vm",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 const created = yield* stack.deploy(
45 Effect.gen(function* () {
46 const source = yield* GCP.VMMigration.Source("VmSource", {
47 aws: dummyAws,
48 });
49 const target = yield* GCP.VMMigration.Target("VmLanding");
50 return yield* GCP.VMMigration.SourcesMigratingVm("Web", {
51 source: source.name,
52 sourceVmId: "i-0123456789abcdef0",
53 displayName: "web-1",
54 description: "web tier",
55 labels: { env: "test" },
56 computeEngineTargetDefaults: {
57 vmName: "web-1",
58 machineType: "n2-standard-2",
59 zone: "us-central1-a",
60 targetProject: target.name,
61 },
62 });
63 }),
64 );
65
66 expect(created.migratingVmId).toEqual(expect.any(String));
67 expect(created.name).toContain("/migratingVms/");
68 expect(created.sourceVmId).toEqual("i-0123456789abcdef0");
69 expect(created.displayName).toEqual("web-1");
70 expect(created.labels).toMatchObject({ env: "test" });
71
72 const fetched =
73 yield* vmmigration.getProjectsLocationsSourcesMigratingVms({
74 name: created.name,
75 });
76 expect(fetched.name).toEqual(created.name);
77 expect(fetched.labels?.env).toEqual("test");
78
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 const source = yield* GCP.VMMigration.Source("VmSource", {
82 aws: dummyAws,
83 });
84 const target = yield* GCP.VMMigration.Target("VmLanding");
85 return yield* GCP.VMMigration.SourcesMigratingVm("Web", {
86 source: source.name,
87 migratingVmId: created.migratingVmId,
88 sourceVmId: "i-0123456789abcdef0",
89 displayName: "web-1-v2",
90 description: "web tier v2",
91 labels: { env: "prod" },
92 computeEngineTargetDefaults: {
93 vmName: "web-1",
94 machineType: "n2-standard-4",
95 zone: "us-central1-a",
96 targetProject: target.name,
97 },
98 });
99 }),
100 );
101
102 expect(updated.name).toEqual(created.name);
103 expect(updated.displayName).toEqual("web-1-v2");
104 expect(updated.labels).toMatchObject({ env: "prod" });
105
106 yield* stack.destroy();
107 const gone = yield* waitUntilGone(
108 vmmigration.getProjectsLocationsSourcesMigratingVms({
109 name: created.name,
110 }),
111 );
112 expect(gone).toEqual("gone");
113 }).pipe(logLevel),
114 {
115 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
116 timeout: 120_000,
117 },
118);