| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as vmwareengine from "@distilled.cloud/gcp/vmwareengine_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | // Private clouds need VMware Engine node quota and bill thousands of dollars |
| 18 | // a month; set GCP_TEST_VMWAREENGINE=1 on an entitled project to opt in. |
| 19 | const runLifecycle = !!process.env.GCP_TEST_VMWAREENGINE && !process.env.FAST; |
| 20 | |
| 21 | const waitUntilGone = (name: string) => |
| 22 | vmwareengine.getProjectsLocationsDatastores({ name }).pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("2 seconds"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getProjectsLocationsDatastores on a missing datastore fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const { project } = yield* GcpEnvironment.current; |
| 37 | |
| 38 | yield* stack.destroy(); |
| 39 | |
| 40 | const error = yield* Effect.flip( |
| 41 | vmwareengine.getProjectsLocationsDatastores({ |
| 42 | name: `projects/${project}/locations/us-central1/datastores/alchemy-ds-missing`, |
| 43 | }), |
| 44 | ); |
| 45 | expect(error._tag).toEqual("NotFound"); |
| 46 | |
| 47 | yield* stack.destroy(); |
| 48 | }).pipe(logLevel), |
| 49 | { |
| 50 | tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"], |
| 51 | timeout: 90_000, |
| 52 | }, |
| 53 | ); |
| 54 | |
| 55 | test.provider.skipIf(!runLifecycle)( |
| 56 | "create, update, and delete a datastore", |
| 57 | (stack) => |
| 58 | Effect.gen(function* () { |
| 59 | const { project } = yield* GcpEnvironment.current; |
| 60 | |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const created = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | return yield* GCP.VMwareEngine.Datastore("Nfs", { |
| 66 | nfsDatastore: { |
| 67 | thirdPartyFileService: { |
| 68 | servers: ["10.0.0.8"], |
| 69 | network: `projects/${project}/global/networks/default`, |
| 70 | fileShare: "vol1", |
| 71 | }, |
| 72 | }, |
| 73 | description: "alchemy-test-ds", |
| 74 | }); |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(created.name).toContain("/datastores/"); |
| 79 | expect(created.datastoreId).toEqual(expect.any(String)); |
| 80 | expect(created.location).toEqual("us-central1"); |
| 81 | expect(created.description).toEqual("alchemy-test-ds"); |
| 82 | |
| 83 | const fetched = yield* vmwareengine.getProjectsLocationsDatastores({ |
| 84 | name: created.name, |
| 85 | }); |
| 86 | expect(fetched.name).toEqual(created.name); |
| 87 | expect(fetched.description).toContain("alchemy-id="); |
| 88 | expect(fetched.description).toContain("alchemy-test-ds"); |
| 89 | |
| 90 | const updated = yield* stack.deploy( |
| 91 | Effect.gen(function* () { |
| 92 | return yield* GCP.VMwareEngine.Datastore("Nfs", { |
| 93 | datastoreId: created.datastoreId, |
| 94 | nfsDatastore: created.nfsDatastore ?? { |
| 95 | thirdPartyFileService: { |
| 96 | servers: ["10.0.0.8"], |
| 97 | network: `projects/${project}/global/networks/default`, |
| 98 | fileShare: "vol1", |
| 99 | }, |
| 100 | }, |
| 101 | description: "alchemy-prod-ds", |
| 102 | }); |
| 103 | }), |
| 104 | ); |
| 105 | |
| 106 | expect(updated.name).toEqual(created.name); |
| 107 | expect(updated.description).toEqual("alchemy-prod-ds"); |
| 108 | |
| 109 | const refetched = yield* vmwareengine.getProjectsLocationsDatastores({ |
| 110 | name: created.name, |
| 111 | }); |
| 112 | expect(refetched.description).toContain("alchemy-prod-ds"); |
| 113 | expect(refetched.description).toContain("alchemy-id="); |
| 114 | |
| 115 | yield* stack.destroy(); |
| 116 | |
| 117 | const gone = yield* waitUntilGone(created.name); |
| 118 | expect(gone).toEqual("gone"); |
| 119 | }).pipe(logLevel), |
| 120 | { |
| 121 | tags: ["provider:gcp", "provider:gcp:vmwareengine", "live"], |
| 122 | timeout: 120_000, |
| 123 | }, |
| 124 | ); |