| 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 | region, |
| 10 | runLifecycle, |
| 11 | waitUntilGone, |
| 12 | } from "./common.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getAdminProjectsLocationsReservations on a missing reservation 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.getAdminProjectsLocationsReservations({ |
| 26 | name: `projects/${project}/locations/${region}/reservations/alchemy-missing-reservation`, |
| 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 reservation", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const created = yield* stack.deploy( |
| 46 | Effect.gen(function* () { |
| 47 | return yield* GCP.PubSubLite.AdminReservation("Capacity", { |
| 48 | location: region, |
| 49 | throughputCapacity: "4", |
| 50 | }); |
| 51 | }), |
| 52 | ); |
| 53 | |
| 54 | expect(created.name).toContain("/reservations/"); |
| 55 | expect(created.reservationId).toContain("+alc."); |
| 56 | expect(created.location).toEqual(region); |
| 57 | expect(created.throughputCapacity).toEqual("4"); |
| 58 | |
| 59 | const fetched = yield* pubsublite.getAdminProjectsLocationsReservations({ |
| 60 | name: created.name, |
| 61 | }); |
| 62 | expect(fetched.name).toEqual(created.name); |
| 63 | expect(fetched.throughputCapacity).toEqual("4"); |
| 64 | |
| 65 | const updated = yield* stack.deploy( |
| 66 | Effect.gen(function* () { |
| 67 | return yield* GCP.PubSubLite.AdminReservation("Capacity", { |
| 68 | reservationId: created.reservationId, |
| 69 | location: region, |
| 70 | throughputCapacity: "8", |
| 71 | }); |
| 72 | }), |
| 73 | ); |
| 74 | |
| 75 | expect(updated.name).toEqual(created.name); |
| 76 | expect(updated.throughputCapacity).toEqual("8"); |
| 77 | |
| 78 | const refetched = yield* pubsublite.getAdminProjectsLocationsReservations( |
| 79 | { |
| 80 | name: created.name, |
| 81 | }, |
| 82 | ); |
| 83 | expect(refetched.throughputCapacity).toEqual("8"); |
| 84 | |
| 85 | yield* stack.destroy(); |
| 86 | |
| 87 | const gone = yield* waitUntilGone( |
| 88 | pubsublite.getAdminProjectsLocationsReservations({ |
| 89 | name: created.name, |
| 90 | }), |
| 91 | ); |
| 92 | expect(gone).toEqual("gone"); |
| 93 | }).pipe(logLevel), |
| 94 | { |
| 95 | tags: ["provider:gcp", "provider:gcp:pubsublite", "live"], |
| 96 | timeout: 90_000, |
| 97 | }, |
| 98 | ); |