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 networkconnectivity from "@distilled.cloud/gcp/networkconnectivity_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 | const runLifecycle = !process.env.FAST; |
| 15 | |
| 16 | const waitUntilGone = (name: string) => |
| 17 | networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigs({ name }).pipe( |
| 18 | Effect.as("found" as const), |
| 19 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 20 | Effect.repeat({ |
| 21 | schedule: Schedule.spaced("2 seconds"), |
| 22 | until: (status) => status === "gone", |
| 23 | times: 10, |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | test.provider( |
| 28 | "getProjectsLocationsMulticloudDataTransferConfigs on a missing config fails with a typed tag", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | const { project } = yield* GcpEnvironment.current; |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const error = yield* Effect.flip( |
| 35 | networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigs({ |
| 36 | name: `projects/${project}/locations/us-central1/multicloudDataTransferConfigs/alchemy-missing`, |
| 37 | }), |
| 38 | ); |
| 39 | expect(error._tag).toEqual("NotFound"); |
| 40 | |
| 41 | yield* stack.destroy(); |
| 42 | }).pipe(logLevel), |
| 43 | { |
| 44 | tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"], |
| 45 | timeout: 90_000, |
| 46 | }, |
| 47 | ); |
| 48 | |
| 49 | test.provider.skipIf(!runLifecycle)( |
| 50 | "create, update, and delete a multicloud data transfer config", |
| 51 | (stack) => |
| 52 | Effect.gen(function* () { |
| 53 | yield* stack.destroy(); |
| 54 | |
| 55 | const created = yield* stack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | return yield* GCP.NetworkConnectivity.MulticloudDataTransferConfig("Dte", { |
| 58 | location: "europe-west1", |
| 59 | description: "dte a", |
| 60 | services: { "cloud-storage": {}, "compute-engine": {} }, |
| 61 | labels: { env: "test" }, |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.name).toContain("/multicloudDataTransferConfigs/"); |
| 67 | expect(created.location).toEqual("europe-west1"); |
| 68 | expect(created.description).toEqual("dte a"); |
| 69 | expect(created.labels).toMatchObject({ env: "test" }); |
| 70 | expect(created.multicloudDataTransferConfigId).toEqual(expect.any(String)); |
| 71 | |
| 72 | const fetched = yield* networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigs({ |
| 73 | name: created.name, |
| 74 | }); |
| 75 | expect(fetched.name).toEqual(created.name); |
| 76 | expect(fetched.description).toEqual("dte a"); |
| 77 | expect(fetched.labels?.env).toEqual("test"); |
| 78 | expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual( |
| 79 | true, |
| 80 | ); |
| 81 | |
| 82 | const updated = yield* stack.deploy( |
| 83 | Effect.gen(function* () { |
| 84 | return yield* GCP.NetworkConnectivity.MulticloudDataTransferConfig("Dte", { |
| 85 | multicloudDataTransferConfigId: created.multicloudDataTransferConfigId, |
| 86 | location: created.location, |
| 87 | description: "dte b", |
| 88 | labels: { env: "prod", role: "dte" }, |
| 89 | }); |
| 90 | }), |
| 91 | ); |
| 92 | |
| 93 | expect(updated.name).toEqual(created.name); |
| 94 | expect(updated.description).toEqual("dte b"); |
| 95 | expect(updated.labels).toMatchObject({ env: "prod", role: "dte" }); |
| 96 | |
| 97 | const refetched = |
| 98 | yield* networkconnectivity.getProjectsLocationsMulticloudDataTransferConfigs({ |
| 99 | name: created.name, |
| 100 | }); |
| 101 | expect(refetched.description).toEqual("dte b"); |
| 102 | expect(refetched.labels?.env).toEqual("prod"); |
| 103 | expect(refetched.labels?.role).toEqual("dte"); |
| 104 | |
| 105 | yield* stack.destroy(); |
| 106 | |
| 107 | const gone = yield* waitUntilGone(created.name); |
| 108 | expect(gone).toEqual("gone"); |
| 109 | }).pipe(logLevel), |
| 110 | { |
| 111 | tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"], |
| 112 | timeout: 180_000, |
| 113 | }, |
| 114 | ); |