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 pubsub from "@distilled.cloud/gcp/pubsub_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 = (name: string) => |
| 14 | pubsub.getProjectsTopics({ topic: name }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, update, and delete a topic", |
| 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.PubSub.Topic("Events", { |
| 33 | labels: { env: "test" }, |
| 34 | }); |
| 35 | }), |
| 36 | ); |
| 37 | |
| 38 | expect(created.name).toContain("/topics/"); |
| 39 | expect(created.topicId).toEqual(expect.any(String)); |
| 40 | expect(created.labels).toMatchObject({ env: "test" }); |
| 41 | |
| 42 | const fetched = yield* pubsub.getProjectsTopics({ topic: created.name }); |
| 43 | expect(fetched.name).toEqual(created.name); |
| 44 | expect(fetched.labels?.env).toEqual("test"); |
| 45 | |
| 46 | const updated = yield* stack.deploy( |
| 47 | Effect.gen(function* () { |
| 48 | return yield* GCP.PubSub.Topic("Events", { |
| 49 | topicId: created.topicId, |
| 50 | labels: { env: "prod", role: "events" }, |
| 51 | messageRetentionDuration: "86400s", |
| 52 | }); |
| 53 | }), |
| 54 | ); |
| 55 | |
| 56 | expect(updated.name).toEqual(created.name); |
| 57 | expect(updated.labels).toMatchObject({ env: "prod", role: "events" }); |
| 58 | expect(updated.messageRetentionDuration).toEqual("86400s"); |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | const gone = yield* waitUntilGone(created.name); |
| 63 | expect(gone).toEqual("gone"); |
| 64 | }).pipe(logLevel), |
| 65 | { tags: ["provider:gcp", "provider:gcp:pubsub", "live"], timeout: 120_000 }, |
| 66 | ); |