| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as pubsublite from "@distilled.cloud/gcp/pubsublite_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | logLevel, |
| 8 | currentProject, |
| 9 | runLifecycle, |
| 10 | waitUntilGone, |
| 11 | zone, |
| 12 | } from "./common.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getAdminProjectsLocationsSubscriptions on a missing subscription fails with a typed tag", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | const project = yield* currentProject; |
| 21 | |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | const error = yield* Effect.flip( |
| 25 | pubsublite.getAdminProjectsLocationsSubscriptions({ |
| 26 | name: `projects/${project}/locations/${zone}/subscriptions/alchemy-missing-subscription`, |
| 27 | }), |
| 28 | ); |
| 29 | expect(error._tag).toEqual("NotFound"); |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | }).pipe(logLevel), |
| 33 | { |
| 34 | tags: ["provider:gcp", "provider:gcp:pubsublite", "live"], |
| 35 | timeout: 90_000, |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | test.provider.skipIf(!runLifecycle)( |
| 40 | "create, update, and delete a subscription", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const created = yield* stack.deploy( |
| 46 | Effect.gen(function* () { |
| 47 | const topic = yield* GCP.PubSubLite.AdminTopic("Events", { |
| 48 | location: zone, |
| 49 | }); |
| 50 | const subscription = yield* GCP.PubSubLite.AdminSubscription( |
| 51 | "Inbox", |
| 52 | { |
| 53 | location: zone, |
| 54 | topic: topic.name, |
| 55 | deliveryConfig: { |
| 56 | deliveryRequirement: "DELIVER_IMMEDIATELY", |
| 57 | }, |
| 58 | }, |
| 59 | ); |
| 60 | return { topic, subscription }; |
| 61 | }), |
| 62 | ); |
| 63 | |
| 64 | expect(created.subscription.name).toContain("/subscriptions/"); |
| 65 | expect(created.subscription.subscriptionId).toContain("+alc."); |
| 66 | expect(created.subscription.location).toEqual(zone); |
| 67 | expect(created.subscription.topic).toEqual(created.topic.name); |
| 68 | expect(created.subscription.deliveryConfig?.deliveryRequirement).toEqual( |
| 69 | "DELIVER_IMMEDIATELY", |
| 70 | ); |
| 71 | |
| 72 | const fetched = yield* pubsublite.getAdminProjectsLocationsSubscriptions({ |
| 73 | name: created.subscription.name, |
| 74 | }); |
| 75 | expect(fetched.name).toEqual(created.subscription.name); |
| 76 | expect(fetched.topic).toEqual(created.topic.name); |
| 77 | expect(fetched.deliveryConfig?.deliveryRequirement).toEqual( |
| 78 | "DELIVER_IMMEDIATELY", |
| 79 | ); |
| 80 | |
| 81 | const updated = yield* stack.deploy( |
| 82 | Effect.gen(function* () { |
| 83 | const topic = yield* GCP.PubSubLite.AdminTopic("Events", { |
| 84 | topicId: created.topic.topicId, |
| 85 | location: zone, |
| 86 | }); |
| 87 | const subscription = yield* GCP.PubSubLite.AdminSubscription( |
| 88 | "Inbox", |
| 89 | { |
| 90 | subscriptionId: created.subscription.subscriptionId, |
| 91 | location: zone, |
| 92 | topic: topic.name, |
| 93 | deliveryConfig: { |
| 94 | deliveryRequirement: "DELIVER_AFTER_STORED", |
| 95 | }, |
| 96 | }, |
| 97 | ); |
| 98 | return { topic, subscription }; |
| 99 | }), |
| 100 | ); |
| 101 | |
| 102 | expect(updated.subscription.name).toEqual(created.subscription.name); |
| 103 | expect(updated.subscription.deliveryConfig?.deliveryRequirement).toEqual( |
| 104 | "DELIVER_AFTER_STORED", |
| 105 | ); |
| 106 | |
| 107 | const refetched = |
| 108 | yield* pubsublite.getAdminProjectsLocationsSubscriptions({ |
| 109 | name: created.subscription.name, |
| 110 | }); |
| 111 | expect(refetched.deliveryConfig?.deliveryRequirement).toEqual( |
| 112 | "DELIVER_AFTER_STORED", |
| 113 | ); |
| 114 | |
| 115 | yield* stack.destroy(); |
| 116 | |
| 117 | const gone = yield* waitUntilGone( |
| 118 | pubsublite.getAdminProjectsLocationsSubscriptions({ |
| 119 | name: created.subscription.name, |
| 120 | }), |
| 121 | ); |
| 122 | expect(gone).toEqual("gone"); |
| 123 | }).pipe(logLevel), |
| 124 | { |
| 125 | tags: ["provider:gcp", "provider:gcp:pubsublite", "live"], |
| 126 | timeout: 90_000, |
| 127 | }, |
| 128 | ); |