| 1 | import * as GCP from "@/GCP"; |
| 2 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as pubsub from "@distilled.cloud/gcp/pubsub_v1"; |
| 5 | import * as storage from "@distilled.cloud/gcp/storage_v1"; |
| 6 | import { expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const gone = <A, E extends { readonly _tag: string }, R>( |
| 12 | self: Effect.Effect<A, E, R>, |
| 13 | ) => |
| 14 | self.pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchIf( |
| 17 | (error) => error._tag === "NotFound", |
| 18 | () => Effect.succeed("gone" as const), |
| 19 | ), |
| 20 | ); |
| 21 | |
| 22 | test.provider( |
| 23 | "renaming a topic or bucket replaces it and deletes the old one", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | yield* stack.destroy(); |
| 27 | const { project } = yield* GcpEnvironment.current; |
| 28 | const deploy = (suffix: string) => |
| 29 | stack.deploy( |
| 30 | Effect.gen(function* () { |
| 31 | const topic = yield* GCP.PubSub.Topic("Renamed", { |
| 32 | topicId: `alchemy-rename-${suffix}`, |
| 33 | }); |
| 34 | const bucket = yield* GCP.Storage.Bucket("RenamedBucket", { |
| 35 | bucketName: `alchemy-rename-${project}-${suffix}`, |
| 36 | forceDestroy: true, |
| 37 | }); |
| 38 | return { topic: topic.name, bucket: bucket.bucketName }; |
| 39 | }), |
| 40 | ); |
| 41 | const first = yield* deploy("a"); |
| 42 | const second = yield* deploy("b"); |
| 43 | expect(second.topic).not.toEqual(first.topic); |
| 44 | expect(second.bucket).not.toEqual(first.bucket); |
| 45 | expect( |
| 46 | yield* gone(pubsub.getProjectsTopics({ topic: first.topic })), |
| 47 | ).toEqual("gone"); |
| 48 | expect(yield* gone(storage.getBuckets({ bucket: first.bucket }))).toEqual( |
| 49 | "gone", |
| 50 | ); |
| 51 | expect( |
| 52 | yield* gone(pubsub.getProjectsTopics({ topic: second.topic })), |
| 53 | ).toEqual("found"); |
| 54 | yield* stack.destroy(); |
| 55 | }), |
| 56 | { tags: ["provider:gcp", "provider:gcp:pubsub", "live"], timeout: 180_000 }, |
| 57 | ); |