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 { GcpEnvironment } from "@alchemy.run/gcp/Environment"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as networkconnectivity from "@distilled.cloud/gcp/networkconnectivity_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { DEFAULT_NETWORK, defaultNetworkSelfLink } from "../networkQuota.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const waitUntilGone = (name: string) => |
| 16 | networkconnectivity.getProjectsLocationsInternalRanges({ name }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("1 second"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | test.provider( |
| 27 | "getProjectsLocationsInternalRanges on a missing range fails with NotFound", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | const { project } = yield* GcpEnvironment.current; |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const error = yield* Effect.flip( |
| 34 | networkconnectivity.getProjectsLocationsInternalRanges({ |
| 35 | name: `projects/${project}/locations/global/internalRanges/alchemy-ir-missing`, |
| 36 | }), |
| 37 | ); |
| 38 | expect(error._tag).toBe("NotFound"); |
| 39 | |
| 40 | const page = yield* networkconnectivity.listProjectsLocationsInternalRanges({ |
| 41 | parent: `projects/${project}/locations/global`, |
| 42 | pageSize: 100, |
| 43 | }); |
| 44 | expect((page.internalRanges ?? []).map((range) => range.name)).not.toContain( |
| 45 | `projects/${project}/locations/global/internalRanges/alchemy-ir-missing`, |
| 46 | ); |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | }).pipe(logLevel), |
| 50 | { |
| 51 | tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"], |
| 52 | timeout: 90_000, |
| 53 | }, |
| 54 | ); |
| 55 | |
| 56 | test.provider.skipIf(!!process.env.FAST)( |
| 57 | "create, update, and delete an internal range", |
| 58 | (stack) => |
| 59 | Effect.gen(function* () { |
| 60 | const { project } = yield* GcpEnvironment.current; |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const created = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | const range = yield* GCP.NetworkConnectivity.InternalRange("Reserved", { |
| 66 | network: defaultNetworkSelfLink(project), |
| 67 | usage: "FOR_VPC", |
| 68 | peering: "FOR_SELF", |
| 69 | ipCidrRange: "172.20.10.0/24", |
| 70 | description: "range a", |
| 71 | labels: { env: "test" }, |
| 72 | }); |
| 73 | return { range }; |
| 74 | }), |
| 75 | ); |
| 76 | |
| 77 | expect(created.range.name).toContain("/internalRanges/"); |
| 78 | expect(created.range.name).toContain("/locations/global/"); |
| 79 | expect(created.range.internalRangeId).toEqual(expect.any(String)); |
| 80 | expect(created.range.location).toEqual("global"); |
| 81 | expect(created.range.project).toEqual(project); |
| 82 | expect(created.range.networkName).toEqual(DEFAULT_NETWORK); |
| 83 | expect(created.range.usage).toEqual("FOR_VPC"); |
| 84 | expect(created.range.peering).toEqual("FOR_SELF"); |
| 85 | expect(created.range.ipCidrRange).toEqual("172.20.10.0/24"); |
| 86 | expect(created.range.description).toEqual("range a"); |
| 87 | expect(created.range.labels).toMatchObject({ env: "test" }); |
| 88 | expect(created.range.createTime).toEqual(expect.any(String)); |
| 89 | |
| 90 | const fetched = yield* networkconnectivity.getProjectsLocationsInternalRanges({ |
| 91 | name: created.range.name, |
| 92 | }); |
| 93 | expect(fetched.name).toEqual(created.range.name); |
| 94 | expect(fetched.ipCidrRange).toEqual("172.20.10.0/24"); |
| 95 | expect(fetched.usage).toEqual("FOR_VPC"); |
| 96 | expect(fetched.peering).toEqual("FOR_SELF"); |
| 97 | expect(fetched.description).toEqual("range a"); |
| 98 | expect(fetched.labels?.env).toEqual("test"); |
| 99 | expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual( |
| 100 | true, |
| 101 | ); |
| 102 | |
| 103 | const updated = yield* stack.deploy( |
| 104 | Effect.gen(function* () { |
| 105 | return yield* GCP.NetworkConnectivity.InternalRange("Reserved", { |
| 106 | internalRangeId: created.range.internalRangeId, |
| 107 | network: defaultNetworkSelfLink(project), |
| 108 | usage: "FOR_VPC", |
| 109 | peering: "FOR_SELF", |
| 110 | ipCidrRange: "172.20.10.0/24", |
| 111 | description: "range b", |
| 112 | labels: { env: "prod", role: "ipam" }, |
| 113 | }); |
| 114 | }), |
| 115 | ); |
| 116 | |
| 117 | expect(updated.name).toEqual(created.range.name); |
| 118 | expect(updated.internalRangeId).toEqual(created.range.internalRangeId); |
| 119 | expect(updated.description).toEqual("range b"); |
| 120 | expect(updated.labels).toMatchObject({ env: "prod", role: "ipam" }); |
| 121 | expect(updated.ipCidrRange).toEqual("172.20.10.0/24"); |
| 122 | |
| 123 | const refetched = yield* networkconnectivity.getProjectsLocationsInternalRanges({ |
| 124 | name: created.range.name, |
| 125 | }); |
| 126 | expect(refetched.description).toEqual("range b"); |
| 127 | expect(refetched.labels?.env).toEqual("prod"); |
| 128 | expect(refetched.labels?.role).toEqual("ipam"); |
| 129 | expect(refetched.ipCidrRange).toEqual("172.20.10.0/24"); |
| 130 | |
| 131 | yield* stack.destroy(); |
| 132 | |
| 133 | const gone = yield* waitUntilGone(created.range.name); |
| 134 | expect(gone).toEqual("gone"); |
| 135 | }).pipe(logLevel), |
| 136 | { |
| 137 | tags: ["provider:gcp", "provider:gcp:networkconnectivity", "live"], |
| 138 | timeout: 600_000, |
| 139 | }, |
| 140 | ); |