| 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 | "getProjectsLocationsSources on a missing source 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.getProjectsLocationsSources({ |
| 25 | name: `projects/${project}/locations/us-central1/sources/alchemy-missing-source`, |
| 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, update, and delete a vm migration source", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | const project = yield* currentProject; |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const created = yield* stack.deploy( |
| 46 | Effect.gen(function* () { |
| 47 | return yield* GCP.VMMigration.Source("Aws", { |
| 48 | location: "us-central1", |
| 49 | description: "aws inventory", |
| 50 | labels: { env: "test" }, |
| 51 | aws: dummyAws, |
| 52 | }); |
| 53 | }), |
| 54 | ); |
| 55 | |
| 56 | expect(created.sourceId).toEqual(expect.any(String)); |
| 57 | expect(created.name).toEqual( |
| 58 | `projects/${project}/locations/us-central1/sources/${created.sourceId}`, |
| 59 | ); |
| 60 | expect(created.location).toEqual("us-central1"); |
| 61 | expect(created.description).toEqual("aws inventory"); |
| 62 | expect(created.labels).toMatchObject({ env: "test" }); |
| 63 | expect(created.aws?.awsRegion).toEqual("us-east-1"); |
| 64 | |
| 65 | const fetched = yield* vmmigration.getProjectsLocationsSources({ |
| 66 | name: created.name, |
| 67 | }); |
| 68 | expect(fetched.name).toEqual(created.name); |
| 69 | expect(fetched.labels?.env).toEqual("test"); |
| 70 | expect(fetched.aws?.awsRegion).toEqual("us-east-1"); |
| 71 | |
| 72 | const updated = yield* stack.deploy( |
| 73 | Effect.gen(function* () { |
| 74 | return yield* GCP.VMMigration.Source("Aws", { |
| 75 | sourceId: created.sourceId, |
| 76 | location: "us-central1", |
| 77 | description: "aws inventory v2", |
| 78 | labels: { env: "prod" }, |
| 79 | aws: dummyAws, |
| 80 | }); |
| 81 | }), |
| 82 | ); |
| 83 | |
| 84 | expect(updated.name).toEqual(created.name); |
| 85 | expect(updated.description).toEqual("aws inventory v2"); |
| 86 | expect(updated.labels).toMatchObject({ env: "prod" }); |
| 87 | |
| 88 | yield* stack.destroy(); |
| 89 | const gone = yield* waitUntilGone( |
| 90 | vmmigration.getProjectsLocationsSources({ name: created.name }), |
| 91 | ); |
| 92 | expect(gone).toEqual("gone"); |
| 93 | }).pipe(logLevel), |
| 94 | { |
| 95 | tags: ["provider:gcp", "provider:gcp:vmmigration", "live"], |
| 96 | timeout: 120_000, |
| 97 | }, |
| 98 | ); |