| 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 { |
| 7 | logLevel, |
| 8 | currentProject, |
| 9 | runSlowLifecycle, |
| 10 | waitUntilGone, |
| 11 | } from "./common.ts"; |
| 12 | import { withNetworkSlot } from "../networkQuota.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getProjectsLocationsPrivateConnections on a missing connection fails with a typed tag", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | const project = yield* currentProject; |
| 21 | |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | const error = yield* Effect.flip( |
| 25 | datamigration.getProjectsLocationsPrivateConnections({ |
| 26 | name: `projects/${project}/locations/us-central1/privateConnections/alchemy-missing-pconn`, |
| 27 | }), |
| 28 | ); |
| 29 | expect(error._tag).toEqual("NotFound"); |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | }).pipe(logLevel), |
| 33 | { |
| 34 | tags: ["provider:gcp", "provider:gcp:datamigration", "live"], |
| 35 | timeout: 90_000, |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | test.provider.skipIf(!runSlowLifecycle)( |
| 40 | "create and delete a private connection", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | const project = yield* currentProject; |
| 44 | |
| 45 | yield* stack.destroy(); |
| 46 | |
| 47 | const created = yield* stack.deploy( |
| 48 | Effect.gen(function* () { |
| 49 | const network = yield* GCP.Compute.Network("DmsVpc", { |
| 50 | autoCreateSubnetworks: false, |
| 51 | }); |
| 52 | const peering = yield* GCP.DataMigration.PrivateConnection( |
| 53 | "DmsPeer", |
| 54 | { |
| 55 | location: "us-central1", |
| 56 | displayName: "dms-peer", |
| 57 | labels: { env: "test" }, |
| 58 | skipValidation: true, |
| 59 | vpcPeeringConfig: { |
| 60 | vpcName: network.networkName, |
| 61 | subnet: "10.8.0.0/29", |
| 62 | }, |
| 63 | }, |
| 64 | ); |
| 65 | return { network, peering }; |
| 66 | }), |
| 67 | ); |
| 68 | |
| 69 | expect(created.peering.privateConnectionId).toEqual(expect.any(String)); |
| 70 | expect(created.peering.name).toEqual( |
| 71 | `projects/${project}/locations/us-central1/privateConnections/${created.peering.privateConnectionId}`, |
| 72 | ); |
| 73 | expect(created.peering.location).toEqual("us-central1"); |
| 74 | expect(created.peering.displayName).toEqual("dms-peer"); |
| 75 | expect(created.peering.labels).toMatchObject({ env: "test" }); |
| 76 | expect(created.peering.vpcPeeringConfig?.subnet).toEqual("10.8.0.0/29"); |
| 77 | |
| 78 | const fetched = |
| 79 | yield* datamigration.getProjectsLocationsPrivateConnections({ |
| 80 | name: created.peering.name, |
| 81 | }); |
| 82 | expect(fetched.name).toEqual(created.peering.name); |
| 83 | expect(fetched.displayName).toEqual("dms-peer"); |
| 84 | expect(fetched.labels?.env).toEqual("test"); |
| 85 | expect(fetched.vpcPeeringConfig?.subnet).toEqual("10.8.0.0/29"); |
| 86 | |
| 87 | yield* stack.destroy(); |
| 88 | const gone = yield* waitUntilGone( |
| 89 | datamigration.getProjectsLocationsPrivateConnections({ |
| 90 | name: created.peering.name, |
| 91 | }), |
| 92 | ); |
| 93 | expect(gone).toEqual("gone"); |
| 94 | }).pipe(logLevel, withNetworkSlot), |
| 95 | { |
| 96 | tags: ["provider:gcp", "provider:gcp:datamigration", "live"], |
| 97 | timeout: 1_500_000, |
| 98 | }, |
| 99 | ); |