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

main
ts 158 lines 5.47 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, runSlowLifecycle, waitUntilGone } from "./common.ts";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 test.provider(
11 "getProjectsLocationsMigrationJobs on a missing job 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.getProjectsLocationsMigrationJobs({
20 name: `projects/${project}/locations/us-central1/migrationJobs/alchemy-missing-job`,
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.skipIf(!runSlowLifecycle)(
34 "create, update, and delete a mysql to cloudsql migration job",
35 (stack) =>
36 Effect.gen(function* () {
37 const project = yield* currentProject;
38
39 yield* stack.destroy();
40
41 const created = yield* stack.deploy(
42 Effect.gen(function* () {
43 const source = yield* GCP.DataMigration.ConnectionProfile("MysqlSrc", {
44 location: "us-central1",
45 displayName: "job-src",
46 mysql: {
47 host: "10.0.0.8",
48 port: 3306,
49 username: "alchemy",
50 password: "AlchemyTestPass1",
51 },
52 });
53 const dest = yield* GCP.DataMigration.ConnectionProfile("MysqlDest", {
54 location: "us-central1",
55 displayName: "job-dest",
56 cloudsql: {
57 settings: {
58 sourceId: source.name,
59 databaseVersion: "MYSQL_8_0",
60 tier: "db-n1-standard-1",
61 rootPassword: "AlchemyTestPass1",
62 dataDiskSizeGb: "10",
63 },
64 },
65 });
66 const job = yield* GCP.DataMigration.MigrationJob("Replica", {
67 location: "us-central1",
68 displayName: "mysql-replica",
69 labels: { env: "test" },
70 type: "CONTINUOUS",
71 source: source.name,
72 destination: dest.name,
73 staticIpConnectivity: {},
74 });
75 return { source, dest, job };
76 }),
77 );
78
79 expect(created.job.migrationJobId).toEqual(expect.any(String));
80 expect(created.job.name).toEqual(
81 `projects/${project}/locations/us-central1/migrationJobs/${created.job.migrationJobId}`,
82 );
83 expect(created.job.type).toEqual("CONTINUOUS");
84 expect(created.job.source).toEqual(created.source.name);
85 expect(created.job.destination).toEqual(created.dest.name);
86 expect(created.job.labels).toMatchObject({ env: "test" });
87
88 const fetched = yield* datamigration.getProjectsLocationsMigrationJobs({
89 name: created.job.name,
90 });
91 expect(fetched.name).toEqual(created.job.name);
92 expect(fetched.displayName).toEqual("mysql-replica");
93 expect(fetched.labels?.env).toEqual("test");
94
95 const updated = yield* stack.deploy(
96 Effect.gen(function* () {
97 const source = yield* GCP.DataMigration.ConnectionProfile("MysqlSrc", {
98 connectionProfileId: created.source.connectionProfileId,
99 location: "us-central1",
100 displayName: "job-src",
101 mysql: {
102 host: "10.0.0.8",
103 port: 3306,
104 username: "alchemy",
105 },
106 });
107 const dest = yield* GCP.DataMigration.ConnectionProfile("MysqlDest", {
108 connectionProfileId: created.dest.connectionProfileId,
109 location: "us-central1",
110 displayName: "job-dest",
111 cloudsql: {
112 settings: {
113 sourceId: source.name,
114 databaseVersion: "MYSQL_8_0",
115 tier: "db-n1-standard-1",
116 dataDiskSizeGb: "10",
117 },
118 },
119 });
120 const job = yield* GCP.DataMigration.MigrationJob("Replica", {
121 migrationJobId: created.job.migrationJobId,
122 location: "us-central1",
123 displayName: "mysql-replica-v2",
124 labels: { env: "prod", team: "dms" },
125 type: "CONTINUOUS",
126 source: source.name,
127 destination: dest.name,
128 staticIpConnectivity: {},
129 });
130 return { source, dest, job };
131 }),
132 );
133
134 expect(updated.job.name).toEqual(created.job.name);
135 expect(updated.job.displayName).toEqual("mysql-replica-v2");
136 expect(updated.job.labels).toMatchObject({ env: "prod", team: "dms" });
137
138 const fetchedUpdate = yield* datamigration.getProjectsLocationsMigrationJobs({
139 name: updated.job.name,
140 });
141 expect(fetchedUpdate.displayName).toEqual("mysql-replica-v2");
142 expect(fetchedUpdate.labels?.team).toEqual("dms");
143
144 yield* stack.destroy();
145 const gone = yield* waitUntilGone(
146 datamigration.getProjectsLocationsMigrationJobs({
147 name: created.job.name,
148 }),
149 );
150 expect(gone).toEqual("gone");
151 }).pipe(logLevel),
152 // The Cloud SQL destination profile provisions an instance (20–40 minutes).
153 {
154 tags: ["provider:gcp", "provider:gcp:datamigration", "live"],
155 timeout: 3_600_000,
156 retry: 0,
157 },
158 );