| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as datamigration from "@distilled.cloud/gcp/datamigration_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 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 | "getProjectsLocationsConnectionProfiles on a missing profile 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.getProjectsLocationsConnectionProfiles({ |
| 20 | name: `projects/${project}/locations/us-central1/connectionProfiles/alchemy-missing-profile`, |
| 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, update, and delete a mysql connection profile", |
| 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 | return yield* GCP.DataMigration.ConnectionProfile("MysqlSrc", { |
| 44 | location: "us-central1", |
| 45 | displayName: "mysql-src", |
| 46 | labels: { env: "test" }, |
| 47 | mysql: { |
| 48 | host: "10.0.0.8", |
| 49 | port: 3306, |
| 50 | username: "alchemy", |
| 51 | password: "AlchemyTestPass1", |
| 52 | }, |
| 53 | }); |
| 54 | }), |
| 55 | ); |
| 56 | |
| 57 | expect(created.connectionProfileId).toEqual(expect.any(String)); |
| 58 | expect(created.name).toEqual( |
| 59 | `projects/${project}/locations/us-central1/connectionProfiles/${created.connectionProfileId}`, |
| 60 | ); |
| 61 | expect(created.location).toEqual("us-central1"); |
| 62 | expect(created.displayName).toEqual("mysql-src"); |
| 63 | expect(created.labels).toMatchObject({ env: "test" }); |
| 64 | expect(created.mysql?.host).toEqual("10.0.0.8"); |
| 65 | expect(created.mysql?.port).toEqual(3306); |
| 66 | expect(created.mysql?.username).toEqual("alchemy"); |
| 67 | expect(created.mysql?.password).toBeUndefined(); |
| 68 | |
| 69 | const fetched = |
| 70 | yield* datamigration.getProjectsLocationsConnectionProfiles({ |
| 71 | name: created.name, |
| 72 | }); |
| 73 | expect(fetched.name).toEqual(created.name); |
| 74 | expect(fetched.displayName).toEqual("mysql-src"); |
| 75 | expect(fetched.labels?.env).toEqual("test"); |
| 76 | expect(fetched.mysql?.host).toEqual("10.0.0.8"); |
| 77 | expect(fetched.mysql?.password).toBeUndefined(); |
| 78 | |
| 79 | const updated = yield* stack.deploy( |
| 80 | Effect.gen(function* () { |
| 81 | return yield* GCP.DataMigration.ConnectionProfile("MysqlSrc", { |
| 82 | connectionProfileId: created.connectionProfileId, |
| 83 | location: "us-central1", |
| 84 | displayName: "mysql-src-v2", |
| 85 | labels: { env: "prod", team: "dms" }, |
| 86 | mysql: { |
| 87 | host: "10.0.0.8", |
| 88 | port: 3306, |
| 89 | username: "alchemy", |
| 90 | }, |
| 91 | }); |
| 92 | }), |
| 93 | ); |
| 94 | |
| 95 | expect(updated.name).toEqual(created.name); |
| 96 | expect(updated.displayName).toEqual("mysql-src-v2"); |
| 97 | expect(updated.labels).toMatchObject({ env: "prod", team: "dms" }); |
| 98 | |
| 99 | const fetchedUpdate = |
| 100 | yield* datamigration.getProjectsLocationsConnectionProfiles({ |
| 101 | name: updated.name, |
| 102 | }); |
| 103 | expect(fetchedUpdate.displayName).toEqual("mysql-src-v2"); |
| 104 | expect(fetchedUpdate.labels?.team).toEqual("dms"); |
| 105 | |
| 106 | yield* stack.destroy(); |
| 107 | const gone = yield* waitUntilGone( |
| 108 | datamigration.getProjectsLocationsConnectionProfiles({ |
| 109 | name: created.name, |
| 110 | }), |
| 111 | ); |
| 112 | expect(gone).toEqual("gone"); |
| 113 | }).pipe(logLevel), |
| 114 | { |
| 115 | tags: ["provider:gcp", "provider:gcp:datamigration", "live"], |
| 116 | timeout: 90_000, |
| 117 | }, |
| 118 | ); |