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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as compute from "@distilled.cloud/gcp/compute_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const waitUntilGone = (project: string, region: string, addressName: string) => |
| 14 | compute.getAddresses({ project, region, address: addressName }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("2 seconds"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, update, and delete a regional address", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | return yield* GCP.Compute.Address("Ingress", { |
| 33 | region: "us-central1", |
| 34 | labels: { env: "test" }, |
| 35 | }); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | expect(created.addressName).toEqual(expect.any(String)); |
| 40 | expect(created.address).toEqual(expect.any(String)); |
| 41 | expect(created.region).toEqual("us-central1"); |
| 42 | expect(created.addressType).toEqual("EXTERNAL"); |
| 43 | expect(created.networkTier).toEqual("PREMIUM"); |
| 44 | expect(created.labels).toMatchObject({ env: "test" }); |
| 45 | expect(created.status).toEqual(expect.stringMatching(/RESERVED|IN_USE/)); |
| 46 | |
| 47 | const fetched = yield* compute.getAddresses({ |
| 48 | project: created.project, |
| 49 | region: created.region, |
| 50 | address: created.addressName, |
| 51 | }); |
| 52 | expect(fetched.name).toEqual(created.addressName); |
| 53 | expect(fetched.address).toEqual(created.address); |
| 54 | expect(fetched.labels?.env).toEqual("test"); |
| 55 | |
| 56 | const updated = yield* stack.deploy( |
| 57 | Effect.gen(function* () { |
| 58 | return yield* GCP.Compute.Address("Ingress", { |
| 59 | addressName: created.addressName, |
| 60 | region: "us-central1", |
| 61 | labels: { env: "prod", role: "ingress" }, |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(updated.addressName).toEqual(created.addressName); |
| 67 | expect(updated.address).toEqual(created.address); |
| 68 | expect(updated.labels).toMatchObject({ env: "prod", role: "ingress" }); |
| 69 | |
| 70 | const fetchedUpdated = yield* compute.getAddresses({ |
| 71 | project: updated.project, |
| 72 | region: updated.region, |
| 73 | address: updated.addressName, |
| 74 | }); |
| 75 | expect(fetchedUpdated.labels?.env).toEqual("prod"); |
| 76 | expect(fetchedUpdated.labels?.role).toEqual("ingress"); |
| 77 | |
| 78 | yield* stack.destroy(); |
| 79 | |
| 80 | const gone = yield* waitUntilGone(created.project, created.region, created.addressName); |
| 81 | expect(gone).toEqual("gone"); |
| 82 | }).pipe(logLevel), |
| 83 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 84 | ); |