@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 78 lines 2.56 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 eventarc from "@distilled.cloud/gcp/eventarc_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const LOCATION = "us-central1";
14
15 const waitUntilGone = (name: string) =>
16 eventarc.getProjectsLocationsChannels({ name }).pipe(
17 Effect.as("found" as const),
18 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
19 Effect.repeat({
20 schedule: Schedule.spaced("2 seconds"),
21 until: (status) => status === "gone",
22 times: 10,
23 }),
24 );
25
26 test.provider(
27 "create, update, and delete an Eventarc channel",
28 (stack) =>
29 Effect.gen(function* () {
30 yield* stack.destroy();
31
32 const created = yield* stack.deploy(
33 Effect.gen(function* () {
34 return yield* GCP.Eventarc.Channel("Events", {
35 location: LOCATION,
36 labels: { env: "test" },
37 });
38 }),
39 );
40
41 expect(created.name).toContain("/channels/");
42 expect(created.channelId).toEqual(expect.any(String));
43 expect(created.location).toEqual(LOCATION);
44 expect(created.labels).toMatchObject({ env: "test" });
45
46 const fetched = yield* eventarc.getProjectsLocationsChannels({
47 name: created.name,
48 });
49 expect(fetched.name).toEqual(created.name);
50 expect(fetched.labels?.env).toEqual("test");
51
52 const updated = yield* stack.deploy(
53 Effect.gen(function* () {
54 return yield* GCP.Eventarc.Channel("Events", {
55 channelId: created.channelId,
56 location: LOCATION,
57 labels: { env: "prod", role: "events" },
58 });
59 }),
60 );
61
62 expect(updated.name).toEqual(created.name);
63 expect(updated.channelId).toEqual(created.channelId);
64 expect(updated.labels).toMatchObject({ env: "prod", role: "events" });
65
66 const refetched = yield* eventarc.getProjectsLocationsChannels({
67 name: created.name,
68 });
69 expect(refetched.labels?.env).toEqual("prod");
70 expect(refetched.labels?.role).toEqual("events");
71
72 yield* stack.destroy();
73
74 const gone = yield* waitUntilGone(created.name);
75 expect(gone).toEqual("gone");
76 }).pipe(logLevel),
77 { tags: ["provider:gcp", "provider:gcp:eventarc", "live"], timeout: 120_000 },
78 );