1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as pubsublite from "@distilled.cloud/gcp/pubsublite_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import {
7 logLevel,
8 currentProject,
9 runLifecycle,
10 waitUntilGone,
11 zone,
12} from "./common.ts";
13
14const { test } = Test.make({ providers: GCP.providers() });
15
16test.provider(
17 "getAdminProjectsLocationsTopics on a missing topic 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.getAdminProjectsLocationsTopics({
26 name: `projects/${project}/locations/${zone}/topics/alchemy-missing-topic`,
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
39test.provider.skipIf(!runLifecycle)(
40 "create, update, and delete a topic",
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.AdminTopic("Events", {
48 location: zone,
49 partitionConfig: {
50 count: 1,
51 capacity: { publishMibPerSec: 4, subscribeMibPerSec: 4 },
52 },
53 retentionConfig: { perPartitionBytes: "32212254720" },
54 });
55 }),
56 );
57
58 expect(created.name).toContain("/topics/");
59 expect(created.topicId).toContain("+alc.");
60 expect(created.location).toEqual(zone);
61 expect(created.partitionConfig?.count).toEqual("1");
62 expect(created.partitionConfig?.capacity?.publishMibPerSec).toEqual(4);
63 expect(created.partitionConfig?.capacity?.subscribeMibPerSec).toEqual(4);
64
65 const fetched = yield* pubsublite.getAdminProjectsLocationsTopics({
66 name: created.name,
67 });
68 expect(fetched.name).toEqual(created.name);
69 expect(fetched.partitionConfig?.capacity?.publishMibPerSec).toEqual(4);
70
71 const updated = yield* stack.deploy(
72 Effect.gen(function* () {
73 return yield* GCP.PubSubLite.AdminTopic("Events", {
74 topicId: created.topicId,
75 location: zone,
76 partitionConfig: {
77 count: 1,
78 capacity: { publishMibPerSec: 4, subscribeMibPerSec: 8 },
79 },
80 retentionConfig: {
81 perPartitionBytes: "32212254720",
82 period: "86400s",
83 },
84 });
85 }),
86 );
87
88 expect(updated.name).toEqual(created.name);
89 expect(updated.partitionConfig?.capacity?.subscribeMibPerSec).toEqual(8);
90 expect(updated.retentionConfig?.period).toEqual("86400s");
91
92 const refetched = yield* pubsublite.getAdminProjectsLocationsTopics({
93 name: created.name,
94 });
95 expect(refetched.partitionConfig?.capacity?.subscribeMibPerSec).toEqual(
96 8,
97 );
98 expect(refetched.retentionConfig?.period).toEqual("86400s");
99
100 yield* stack.destroy();
101
102 const gone = yield* waitUntilGone(
103 pubsublite.getAdminProjectsLocationsTopics({ name: created.name }),
104 );
105 expect(gone).toEqual("gone");
106 }).pipe(logLevel),
107 {
108 tags: ["provider:gcp", "provider:gcp:pubsublite", "live"],
109 timeout: 90_000,
110 },
111);