@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

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