The best way to control Claude Code, Codex and more from any computer or phone

main
ts 90 lines 3.39 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as datamigration from "@distilled.cloud/gcp/datamigration_v1";
5 import * as Effect from "effect/Effect";
6 import { logLevel, currentProject, waitUntilGone } from "./common.ts";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 test.provider(
11 "getProjectsLocationsConversionWorkspacesMappingRules on a missing rule fails with a typed tag",
12 (stack) =>
13 Effect.gen(function* () {
14 const project = yield* currentProject;
15
16 yield* stack.destroy();
17
18 const error = yield* Effect.flip(
19 datamigration.getProjectsLocationsConversionWorkspacesMappingRules({
20 name: `projects/${project}/locations/us-central1/conversionWorkspaces/alchemy-missing-workspace/mappingRules/alchemy-missing-rule`,
21 }),
22 );
23 expect(error._tag).toEqual("NotFound");
24
25 yield* stack.destroy();
26 }).pipe(logLevel),
27 {
28 tags: ["provider:gcp", "provider:gcp:datamigration", "live"],
29 timeout: 90_000,
30 },
31 );
32
33 test.provider(
34 "create and delete a conversion workspace mapping rule",
35 (stack) =>
36 Effect.gen(function* () {
37 yield* stack.destroy();
38
39 const created = yield* stack.deploy(
40 Effect.gen(function* () {
41 const workspace = yield* GCP.DataMigration.ConversionWorkspace("OracleToPg", {
42 location: "us-central1",
43 displayName: "rule-workspace",
44 source: { engine: "ORACLE", version: "11" },
45 destination: { engine: "POSTGRESQL", version: "14" },
46 });
47 const rule = yield* GCP.DataMigration.ConversionWorkspacesMappingRule("Rename", {
48 conversionWorkspace: workspace.name,
49 location: "us-central1",
50 displayName: "rename-schema",
51 ruleScope: "DATABASE_ENTITY_TYPE_SCHEMA",
52 ruleOrder: "1000",
53 filter: { entities: ["src_schema"] },
54 singleEntityRename: { newName: "dst_schema" },
55 });
56 return { workspace, rule };
57 }),
58 );
59
60 expect(created.rule.mappingRuleId).toEqual(expect.any(String));
61 expect(created.rule.name).toEqual(
62 `${created.workspace.name}/mappingRules/${created.rule.mappingRuleId}`,
63 );
64 expect(created.rule.conversionWorkspace).toEqual(created.workspace.name);
65 expect(created.rule.displayName).toEqual("rename-schema");
66 expect(created.rule.ruleScope).toEqual("DATABASE_ENTITY_TYPE_SCHEMA");
67 expect(created.rule.singleEntityRename?.newName).toEqual("dst_schema");
68
69 const fetched = yield* datamigration.getProjectsLocationsConversionWorkspacesMappingRules({
70 name: created.rule.name,
71 });
72 // The API omits `name` from mapping rules; the fetch by name is the check.
73 expect(fetched.ruleScope).toEqual("DATABASE_ENTITY_TYPE_SCHEMA");
74 expect(fetched.displayName).toMatch(/^\[(alchemy|alc) /);
75 expect(fetched.singleEntityRename?.newName).toEqual("dst_schema");
76 expect(fetched.filter?.entities).toContain("src_schema");
77
78 yield* stack.destroy();
79 const gone = yield* waitUntilGone(
80 datamigration.getProjectsLocationsConversionWorkspacesMappingRules({
81 name: created.rule.name,
82 }),
83 );
84 expect(gone).toEqual("gone");
85 }).pipe(logLevel),
86 {
87 tags: ["provider:gcp", "provider:gcp:datamigration", "live"],
88 timeout: 90_000,
89 },
90 );