The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { GcpEnvironment } from "@alchemy.run/gcp/Environment"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as netapp from "@distilled.cloud/gcp/netapp_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | // Two pools + volume + replication: skip unless explicitly enabled. |
| 15 | // Volumes need a Private Service Access connection to |
| 16 | // `netapp.servicenetworking.goog` on the `default` network (otherwise volume |
| 17 | // create fails with `Please create Service Networking connection with |
| 18 | // service 'netapp.servicenetworking.goog' ...`), and each file provisions its |
| 19 | // own 2 TiB STANDARD pool while the default regional quota |
| 20 | // (StandardStoragePoolCapacityGiBPerRegion = 2048) fits one. Set |
| 21 | // GCP_TEST_NETAPP_VOLUMES=1 on a project with both. |
| 22 | const runLifecycle = !!process.env.GCP_TEST_NETAPP_VOLUMES && !process.env.FAST; |
| 23 | |
| 24 | const waitUntilGone = (name: string) => |
| 25 | netapp.getProjectsLocationsVolumesReplications({ name }).pipe( |
| 26 | Effect.as("found" as const), |
| 27 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 28 | Effect.repeat({ |
| 29 | schedule: Schedule.spaced("2 seconds"), |
| 30 | until: (status) => status === "gone", |
| 31 | times: 10, |
| 32 | }), |
| 33 | ); |
| 34 | |
| 35 | test.provider( |
| 36 | "getProjectsLocationsVolumesReplications on a missing replication fails with a typed tag", |
| 37 | (stack) => |
| 38 | Effect.gen(function* () { |
| 39 | const { project } = yield* GcpEnvironment.current; |
| 40 | |
| 41 | yield* stack.destroy(); |
| 42 | |
| 43 | const error = yield* Effect.flip( |
| 44 | netapp.getProjectsLocationsVolumesReplications({ |
| 45 | name: `projects/${project}/locations/us-central1/volumes/alchemy-netapp-missing/replications/alchemy-repl-missing`, |
| 46 | }), |
| 47 | ); |
| 48 | expect(error._tag).toEqual("NotFound"); |
| 49 | |
| 50 | const page = yield* netapp.listProjectsLocationsVolumesReplications({ |
| 51 | parent: `projects/${project}/locations/us-central1/volumes/-`, |
| 52 | pageSize: 10, |
| 53 | }); |
| 54 | expect((page.replications ?? []).map((item) => item.name)).not.toContain( |
| 55 | `projects/${project}/locations/us-central1/volumes/alchemy-netapp-missing/replications/alchemy-repl-missing`, |
| 56 | ); |
| 57 | |
| 58 | yield* stack.destroy(); |
| 59 | }).pipe(logLevel), |
| 60 | { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 90_000 }, |
| 61 | ); |
| 62 | |
| 63 | test.provider.skipIf(!runLifecycle)( |
| 64 | "create, update, and delete a volume replication", |
| 65 | (stack) => |
| 66 | Effect.gen(function* () { |
| 67 | yield* stack.destroy(); |
| 68 | |
| 69 | const created = yield* stack.deploy( |
| 70 | Effect.gen(function* () { |
| 71 | const sourcePool = yield* GCP.NetApp.StoragePool("Source", { |
| 72 | location: "us-central1", |
| 73 | network: "default", |
| 74 | serviceLevel: "STANDARD", |
| 75 | capacityGib: 2048, |
| 76 | labels: { env: "test" }, |
| 77 | }); |
| 78 | const destPool = yield* GCP.NetApp.StoragePool("Dest", { |
| 79 | location: "us-east4", |
| 80 | network: "default", |
| 81 | serviceLevel: "STANDARD", |
| 82 | capacityGib: 2048, |
| 83 | labels: { env: "test" }, |
| 84 | }); |
| 85 | const volume = yield* GCP.NetApp.Volume("Share", { |
| 86 | location: "us-central1", |
| 87 | storagePool: sourcePool.name, |
| 88 | protocols: ["NFSV3"], |
| 89 | capacityGib: 100, |
| 90 | shareName: "alchrepl", |
| 91 | labels: { env: "test" }, |
| 92 | }); |
| 93 | const replication = yield* GCP.NetApp.VolumesReplication("Dr", { |
| 94 | volume: volume.name, |
| 95 | replicationSchedule: "HOURLY", |
| 96 | destinationVolumeParameters: { |
| 97 | storagePool: destPool.name, |
| 98 | shareName: "alchrepl", |
| 99 | description: "alchemy replica", |
| 100 | }, |
| 101 | description: "alchemy-test-repl", |
| 102 | labels: { env: "test" }, |
| 103 | deleteDestinationVolume: true, |
| 104 | }); |
| 105 | return { sourcePool, destPool, volume, replication }; |
| 106 | }), |
| 107 | ); |
| 108 | |
| 109 | expect(created.replication.name).toContain("/replications/"); |
| 110 | expect(created.replication.replicationId).toEqual(expect.any(String)); |
| 111 | expect(created.replication.volume).toEqual(created.volume.name); |
| 112 | expect(created.replication.description).toEqual("alchemy-test-repl"); |
| 113 | expect(created.replication.labels).toMatchObject({ env: "test" }); |
| 114 | expect(created.replication.replicationSchedule).toEqual("HOURLY"); |
| 115 | |
| 116 | const fetched = yield* netapp.getProjectsLocationsVolumesReplications({ |
| 117 | name: created.replication.name, |
| 118 | }); |
| 119 | expect(fetched.name).toEqual(created.replication.name); |
| 120 | expect(fetched.description).toEqual("alchemy-test-repl"); |
| 121 | expect(fetched.labels?.env).toEqual("test"); |
| 122 | expect(fetched.replicationSchedule).toEqual("HOURLY"); |
| 123 | |
| 124 | const updated = yield* stack.deploy( |
| 125 | Effect.gen(function* () { |
| 126 | const sourcePool = yield* GCP.NetApp.StoragePool("Source", { |
| 127 | storagePoolId: created.sourcePool.storagePoolId, |
| 128 | location: "us-central1", |
| 129 | network: "default", |
| 130 | serviceLevel: "STANDARD", |
| 131 | capacityGib: 2048, |
| 132 | labels: { env: "test" }, |
| 133 | }); |
| 134 | const destPool = yield* GCP.NetApp.StoragePool("Dest", { |
| 135 | storagePoolId: created.destPool.storagePoolId, |
| 136 | location: "us-east4", |
| 137 | network: "default", |
| 138 | serviceLevel: "STANDARD", |
| 139 | capacityGib: 2048, |
| 140 | labels: { env: "test" }, |
| 141 | }); |
| 142 | const volume = yield* GCP.NetApp.Volume("Share", { |
| 143 | volumeId: created.volume.volumeId, |
| 144 | location: "us-central1", |
| 145 | storagePool: sourcePool.name, |
| 146 | protocols: ["NFSV3"], |
| 147 | capacityGib: 100, |
| 148 | shareName: "alchrepl", |
| 149 | labels: { env: "test" }, |
| 150 | }); |
| 151 | const replication = yield* GCP.NetApp.VolumesReplication("Dr", { |
| 152 | volume: volume.name, |
| 153 | replicationId: created.replication.replicationId, |
| 154 | replicationSchedule: "DAILY", |
| 155 | destinationVolumeParameters: { |
| 156 | storagePool: destPool.name, |
| 157 | shareName: "alchrepl", |
| 158 | }, |
| 159 | description: "alchemy-prod-repl", |
| 160 | labels: { env: "prod", role: "dr" }, |
| 161 | deleteDestinationVolume: true, |
| 162 | }); |
| 163 | return { sourcePool, destPool, volume, replication }; |
| 164 | }), |
| 165 | ); |
| 166 | |
| 167 | expect(updated.replication.name).toEqual(created.replication.name); |
| 168 | expect(updated.replication.description).toEqual("alchemy-prod-repl"); |
| 169 | expect(updated.replication.labels).toMatchObject({ |
| 170 | env: "prod", |
| 171 | role: "dr", |
| 172 | }); |
| 173 | expect(updated.replication.replicationSchedule).toEqual("DAILY"); |
| 174 | |
| 175 | const refetched = yield* netapp.getProjectsLocationsVolumesReplications({ |
| 176 | name: created.replication.name, |
| 177 | }); |
| 178 | expect(refetched.description).toEqual("alchemy-prod-repl"); |
| 179 | expect(refetched.labels?.env).toEqual("prod"); |
| 180 | expect(refetched.replicationSchedule).toEqual("DAILY"); |
| 181 | |
| 182 | yield* stack.destroy(); |
| 183 | |
| 184 | const gone = yield* waitUntilGone(created.replication.name); |
| 185 | expect(gone).toEqual("gone"); |
| 186 | }).pipe(logLevel), |
| 187 | { tags: ["provider:gcp", "provider:gcp:netapp", "live"], timeout: 900_000 }, |
| 188 | ); |