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
| 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 servicedirectory from "@distilled.cloud/gcp/servicedirectory_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 waitUntilGone = (name: string) => |
| 14 | servicedirectory.getProjectsLocationsNamespacesServices({ name }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | test.provider( |
| 25 | "create, update, resolve, and delete a service", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | |
| 30 | const created = yield* stack.deploy( |
| 31 | Effect.gen(function* () { |
| 32 | const ns = yield* GCP.ServiceDirectory.Namespace("Services", { |
| 33 | location: "us-central1", |
| 34 | labels: { env: "test" }, |
| 35 | }); |
| 36 | const api = yield* GCP.ServiceDirectory.Service("Api", { |
| 37 | namespace: ns.name, |
| 38 | annotations: { protocol: "http" }, |
| 39 | }); |
| 40 | return { ns, api }; |
| 41 | }), |
| 42 | ); |
| 43 | |
| 44 | expect(created.api.name).toContain("/services/"); |
| 45 | expect(created.api.serviceId).toEqual(expect.any(String)); |
| 46 | expect(created.api.namespace).toEqual(created.ns.name); |
| 47 | expect(created.api.namespaceId).toEqual(created.ns.namespaceId); |
| 48 | expect(created.api.location).toEqual("us-central1"); |
| 49 | expect(created.api.annotations).toMatchObject({ protocol: "http" }); |
| 50 | expect(created.api.uid).toEqual(expect.any(String)); |
| 51 | |
| 52 | const fetched = yield* servicedirectory.getProjectsLocationsNamespacesServices({ |
| 53 | name: created.api.name, |
| 54 | }); |
| 55 | expect(fetched.name).toEqual(created.api.name); |
| 56 | expect(fetched.annotations?.protocol).toEqual("http"); |
| 57 | expect(fetched.annotations?.["alchemy-id"]).toEqual(expect.any(String)); |
| 58 | expect(fetched.uid).toEqual(created.api.uid); |
| 59 | |
| 60 | const resolved = yield* servicedirectory.resolveProjectsLocationsNamespacesServices({ |
| 61 | name: created.api.name, |
| 62 | body: {}, |
| 63 | }); |
| 64 | expect(resolved.service?.name).toEqual(created.api.name); |
| 65 | |
| 66 | const updated = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | const ns = yield* GCP.ServiceDirectory.Namespace("Services", { |
| 69 | namespaceId: created.ns.namespaceId, |
| 70 | location: "us-central1", |
| 71 | labels: { env: "test" }, |
| 72 | }); |
| 73 | const api = yield* GCP.ServiceDirectory.Service("Api", { |
| 74 | namespace: ns.name, |
| 75 | serviceId: created.api.serviceId, |
| 76 | annotations: { protocol: "grpc", role: "api" }, |
| 77 | }); |
| 78 | return { ns, api }; |
| 79 | }), |
| 80 | ); |
| 81 | |
| 82 | expect(updated.api.name).toEqual(created.api.name); |
| 83 | expect(updated.api.uid).toEqual(created.api.uid); |
| 84 | expect(updated.api.annotations).toMatchObject({ |
| 85 | protocol: "grpc", |
| 86 | role: "api", |
| 87 | }); |
| 88 | |
| 89 | const refetched = yield* servicedirectory.getProjectsLocationsNamespacesServices({ |
| 90 | name: created.api.name, |
| 91 | }); |
| 92 | expect(refetched.annotations?.protocol).toEqual("grpc"); |
| 93 | expect(refetched.annotations?.role).toEqual("api"); |
| 94 | |
| 95 | yield* stack.destroy(); |
| 96 | |
| 97 | const gone = yield* waitUntilGone(created.api.name); |
| 98 | expect(gone).toEqual("gone"); |
| 99 | }).pipe(logLevel), |
| 100 | { |
| 101 | tags: ["provider:gcp", "provider:gcp:servicedirectory", "live"], |
| 102 | timeout: 90_000, |
| 103 | }, |
| 104 | ); |