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 "getProjectsLocationsSourcesUtilizationReports on a missing report 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.getProjectsLocationsSourcesUtilizationReports({
25 name: `projects/${project}/locations/us-central1/sources/alchemy-missing-source/utilizationReports/alchemy-missing-report`,
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 and delete a vm migration utilization report",
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("ReportSource", {
47 aws: dummyAws,
48 });
49 return yield* GCP.VMMigration.SourcesUtilizationReport("Week", {
50 source: source.name,
51 timeFrame: "WEEK",
52 displayName: "weekly",
53 vms: [{ vmId: "i-0123456789abcdef0" }],
54 });
55 }),
56 );
57
58 expect(created.utilizationReportId).toEqual(expect.any(String));
59 expect(created.name).toContain("/utilizationReports/");
60 expect(created.timeFrame).toEqual("WEEK");
61 expect(created.displayName).toEqual("weekly");
62
63 const fetched =
64 yield* vmmigration.getProjectsLocationsSourcesUtilizationReports({
65 name: created.name,
66 });
67 expect(fetched.name).toEqual(created.name);
68 expect(fetched.displayName).toContain("alchemy-id=");
69
70 yield* stack.destroy();
71 const gone = yield* waitUntilGone(
72 vmmigration.getProjectsLocationsSourcesUtilizationReports({
73 name: created.name,
74 }),
75 );
76 expect(gone).toEqual("gone");
77 }).pipe(logLevel),
78 {
79 tags: ["provider:gcp", "provider:gcp:vmmigration", "live"],
80 timeout: 120_000,
81 },
82);