1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as migrationcenter from "@distilled.cloud/gcp/migrationcenter_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 waitUntilGone = (name: string) =>
18 migrationcenter.getProjectsLocationsSources({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28test.provider(
29 "create, update, and delete a migration center source",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 yield* stack.destroy();
34
35 const created = yield* stack.deploy(
36 Effect.gen(function* () {
37 return yield* GCP.MigrationCenter.Source("Assets", {
38 location: "us-central1",
39 type: "SOURCE_TYPE_CUSTOM",
40 displayName: "custom assets",
41 description: "inventory feed",
42 priority: 1,
43 });
44 }),
45 );
46
47 expect(created.sourceId).toEqual(expect.any(String));
48 expect(created.name).toEqual(
49 `projects/${project}/locations/us-central1/sources/${created.sourceId}`,
50 );
51 expect(created.project).toEqual(project);
52 expect(created.location).toEqual("us-central1");
53 expect(created.type).toEqual("SOURCE_TYPE_CUSTOM");
54 expect(created.managed ?? false).toEqual(false);
55 expect(created.displayName).toEqual("custom assets");
56 expect(created.description).toEqual("inventory feed");
57 expect(created.priority).toEqual(1);
58
59 const fetched = yield* migrationcenter.getProjectsLocationsSources({
60 name: created.name,
61 });
62 expect(fetched.name).toEqual(created.name);
63 expect(fetched.type).toEqual("SOURCE_TYPE_CUSTOM");
64 expect(fetched.displayName).toEqual("custom assets");
65 expect(fetched.priority).toEqual(1);
66 expect(fetched.description).toContain("alchemy-id=");
67 expect(fetched.description).toContain("inventory feed");
68
69 const updated = yield* stack.deploy(
70 Effect.gen(function* () {
71 return yield* GCP.MigrationCenter.Source("Assets", {
72 sourceId: created.sourceId,
73 location: "us-central1",
74 type: "SOURCE_TYPE_CUSTOM",
75 displayName: "custom assets v2",
76 description: "inventory feed v2",
77 priority: 10,
78 });
79 }),
80 );
81
82 expect(updated.name).toEqual(created.name);
83 expect(updated.sourceId).toEqual(created.sourceId);
84 expect(updated.displayName).toEqual("custom assets v2");
85 expect(updated.description).toEqual("inventory feed v2");
86 expect(updated.priority).toEqual(10);
87
88 const fetchedUpdate = yield* migrationcenter.getProjectsLocationsSources({
89 name: created.name,
90 });
91 expect(fetchedUpdate.displayName).toEqual("custom assets v2");
92 expect(fetchedUpdate.priority).toEqual(10);
93 expect(fetchedUpdate.description).toContain("inventory feed v2");
94
95 yield* stack.destroy();
96
97 const gone = yield* waitUntilGone(created.name);
98 expect(gone).toEqual("gone");
99 }).pipe(logLevel),
100 {
101 tags: ["provider:gcp", "provider:gcp:migrationcenter", "live"],
102 timeout: 180_000,
103 },
104);