| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as vmmigration from "@distilled.cloud/gcp/vmmigration_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | dummyAws, |
| 8 | logLevel, |
| 9 | currentProject, |
| 10 | runSourceLifecycle, |
| 11 | waitUntilGone, |
| 12 | } from "./common.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getProjectsLocationsSourcesDatacenterConnectors on a missing connector fails with a typed tag", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | const project = yield* currentProject; |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const error = yield* Effect.flip( |
| 24 | vmmigration.getProjectsLocationsSourcesDatacenterConnectors({ |
| 25 | name: `projects/${project}/locations/us-central1/sources/alchemy-missing-source/datacenterConnectors/alchemy-missing-connector`, |
| 26 | }), |
| 27 | ); |
| 28 | expect(error._tag).toEqual("NotFound"); |
| 29 | |
| 30 | yield* stack.destroy(); |
| 31 | }).pipe(logLevel), |
| 32 | { |
| 33 | tags: ["provider:gcp", "provider:gcp:vmmigration", "live"], |
| 34 | timeout: 90_000, |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | test.provider.skipIf(!runSourceLifecycle)( |
| 39 | "create and delete a vm migration datacenter connector", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const created = yield* stack.deploy( |
| 45 | Effect.gen(function* () { |
| 46 | const source = yield* GCP.VMMigration.Source("ConnectorSource", { |
| 47 | aws: dummyAws, |
| 48 | }); |
| 49 | return yield* GCP.VMMigration.SourcesDatacenterConnector( |
| 50 | "Appliance", |
| 51 | { |
| 52 | source: source.name, |
| 53 | version: "1.0.0", |
| 54 | }, |
| 55 | ); |
| 56 | }), |
| 57 | ); |
| 58 | |
| 59 | expect(created.datacenterConnectorId).toEqual(expect.any(String)); |
| 60 | expect(created.name).toContain("/datacenterConnectors/"); |
| 61 | expect(created.source).toContain("/sources/"); |
| 62 | expect(created.version).toEqual("1.0.0"); |
| 63 | |
| 64 | const fetched = |
| 65 | yield* vmmigration.getProjectsLocationsSourcesDatacenterConnectors({ |
| 66 | name: created.name, |
| 67 | }); |
| 68 | expect(fetched.name).toEqual(created.name); |
| 69 | expect(fetched.version).toContain("alchemy-id="); |
| 70 | |
| 71 | yield* stack.destroy(); |
| 72 | const gone = yield* waitUntilGone( |
| 73 | vmmigration.getProjectsLocationsSourcesDatacenterConnectors({ |
| 74 | name: created.name, |
| 75 | }), |
| 76 | ); |
| 77 | expect(gone).toEqual("gone"); |
| 78 | }).pipe(logLevel), |
| 79 | { |
| 80 | tags: ["provider:gcp", "provider:gcp:vmmigration", "live"], |
| 81 | timeout: 120_000, |
| 82 | }, |
| 83 | ); |