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 dataplex from "@distilled.cloud/gcp/dataplex_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { withDataplexSlot } from "./quota.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | const RELATED_ENTRY_LINK_TYPE = "projects/dataplex-types/locations/global/entryLinkTypes/related"; |
| 15 | |
| 16 | const waitUntilGone = (name: string) => |
| 17 | dataplex.getProjectsLocationsEntryGroupsEntryLinks({ name }).pipe( |
| 18 | Effect.as("found" as const), |
| 19 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 20 | Effect.repeat({ |
| 21 | schedule: Schedule.spaced("1 second"), |
| 22 | until: (status) => status === "gone", |
| 23 | times: 10, |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | test.provider.skipIf(!!process.env.FAST)( |
| 28 | "create, update, and delete an entry link", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const created = yield* stack.deploy( |
| 34 | Effect.gen(function* () { |
| 35 | const type = yield* GCP.Dataplex.EntryType("Kind", { |
| 36 | location: "us-central1", |
| 37 | displayName: "kind", |
| 38 | }); |
| 39 | const group = yield* GCP.Dataplex.EntryGroup("Catalog", { |
| 40 | location: "us-central1", |
| 41 | displayName: "catalog", |
| 42 | labels: { env: "test" }, |
| 43 | }); |
| 44 | const left = yield* GCP.Dataplex.EntryGroupsEntry("Left", { |
| 45 | entryGroup: group.name, |
| 46 | entryType: type.name, |
| 47 | labels: { env: "test" }, |
| 48 | }); |
| 49 | const right = yield* GCP.Dataplex.EntryGroupsEntry("Right", { |
| 50 | entryGroup: group.name, |
| 51 | entryType: type.name, |
| 52 | labels: { env: "test" }, |
| 53 | }); |
| 54 | const link = yield* GCP.Dataplex.EntryGroupsEntryLink("Related", { |
| 55 | entryGroup: group.name, |
| 56 | entryLinkType: RELATED_ENTRY_LINK_TYPE, |
| 57 | entryReferences: [ |
| 58 | { name: left.name, type: "UNSPECIFIED" }, |
| 59 | { name: right.name, type: "UNSPECIFIED" }, |
| 60 | ], |
| 61 | }); |
| 62 | return { type, group, left, right, link }; |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.link.name).toContain("/entryLinks/"); |
| 67 | expect(created.link.entryGroup).toEqual(created.group.name); |
| 68 | expect(created.link.entryLinkType).toContain("/entryLinkTypes/related"); |
| 69 | expect(created.link.entryReferences).toHaveLength(2); |
| 70 | |
| 71 | const fetched = yield* dataplex.getProjectsLocationsEntryGroupsEntryLinks({ |
| 72 | name: created.link.name, |
| 73 | }); |
| 74 | expect(fetched.name).toEqual(created.link.name); |
| 75 | expect(fetched.entryLinkType).toContain("/entryLinkTypes/related"); |
| 76 | expect(fetched.entryReferences ?? []).toHaveLength(2); |
| 77 | |
| 78 | const updated = yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | const type = yield* GCP.Dataplex.EntryType("Kind", { |
| 81 | entryTypeId: created.type.entryTypeId, |
| 82 | location: "us-central1", |
| 83 | displayName: "kind", |
| 84 | }); |
| 85 | const group = yield* GCP.Dataplex.EntryGroup("Catalog", { |
| 86 | entryGroupId: created.group.entryGroupId, |
| 87 | location: "us-central1", |
| 88 | displayName: "catalog", |
| 89 | labels: { env: "test" }, |
| 90 | }); |
| 91 | const left = yield* GCP.Dataplex.EntryGroupsEntry("Left", { |
| 92 | entryGroup: group.name, |
| 93 | entryId: created.left.entryId, |
| 94 | entryType: type.name, |
| 95 | labels: { env: "test" }, |
| 96 | }); |
| 97 | const right = yield* GCP.Dataplex.EntryGroupsEntry("Right", { |
| 98 | entryGroup: group.name, |
| 99 | entryId: created.right.entryId, |
| 100 | entryType: type.name, |
| 101 | labels: { env: "test" }, |
| 102 | }); |
| 103 | const link = yield* GCP.Dataplex.EntryGroupsEntryLink("Related", { |
| 104 | entryGroup: group.name, |
| 105 | entryLinkId: created.link.entryLinkId, |
| 106 | entryLinkType: RELATED_ENTRY_LINK_TYPE, |
| 107 | entryReferences: [ |
| 108 | { name: left.name, type: "UNSPECIFIED" }, |
| 109 | { name: right.name, type: "UNSPECIFIED" }, |
| 110 | ], |
| 111 | }); |
| 112 | return { type, group, left, right, link }; |
| 113 | }), |
| 114 | ); |
| 115 | |
| 116 | expect(updated.link.name).toEqual(created.link.name); |
| 117 | expect(updated.link.entryLinkType).toContain("/entryLinkTypes/related"); |
| 118 | |
| 119 | yield* stack.destroy(); |
| 120 | const gone = yield* waitUntilGone(created.link.name); |
| 121 | expect(gone).toEqual("gone"); |
| 122 | }).pipe(logLevel, withDataplexSlot), |
| 123 | { tags: ["provider:gcp", "provider:gcp:dataplex", "live"], timeout: 900_000 }, |
| 124 | ); |