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 cnr from "@distilled.cloud/gcp/cloudnumberregistry_v1alpha"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | location, |
| 8 | logLevel, |
| 9 | currentProject, |
| 10 | entitled, |
| 11 | runLifecycle, |
| 12 | waitUntilGone, |
| 13 | } from "./common.ts"; |
| 14 | |
| 15 | const { test } = Test.make({ providers: GCP.providers() }); |
| 16 | |
| 17 | const CIDR = "10.250.0.0/22"; |
| 18 | |
| 19 | test.provider.skipIf(!entitled)( |
| 20 | "getProjectsLocationsCustomRanges on a missing range fails with a typed tag", |
| 21 | (stack) => |
| 22 | Effect.gen(function* () { |
| 23 | const project = yield* currentProject; |
| 24 | |
| 25 | yield* stack.destroy(); |
| 26 | |
| 27 | const error = yield* Effect.flip( |
| 28 | cnr.getProjectsLocationsCustomRanges({ |
| 29 | name: `projects/${project}/locations/${location}/customRanges/alchemy-missing-range`, |
| 30 | }), |
| 31 | ); |
| 32 | expect(error._tag).toEqual("NotFound"); |
| 33 | |
| 34 | yield* stack.destroy(); |
| 35 | }).pipe(logLevel), |
| 36 | { |
| 37 | tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"], |
| 38 | timeout: 90_000, |
| 39 | }, |
| 40 | ); |
| 41 | |
| 42 | test.provider.skipIf(!runLifecycle)( |
| 43 | "create, update, and delete a custom range", |
| 44 | (stack) => |
| 45 | Effect.gen(function* () { |
| 46 | const project = yield* currentProject; |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | |
| 50 | const created = yield* stack.deploy( |
| 51 | Effect.gen(function* () { |
| 52 | const book = yield* GCP.CloudNumberRegistry.RegistryBook("Inventory", { |
| 53 | location, |
| 54 | labels: { env: "test" }, |
| 55 | }); |
| 56 | const realm = yield* GCP.CloudNumberRegistry.Realm("Private", { |
| 57 | location, |
| 58 | registryBook: book.name, |
| 59 | trafficType: "PRIVATE", |
| 60 | managementType: "USER", |
| 61 | ipVersion: "IPV4", |
| 62 | labels: { env: "test" }, |
| 63 | }); |
| 64 | const range = yield* GCP.CloudNumberRegistry.CustomRange("OnPrem", { |
| 65 | location, |
| 66 | realm: realm.name, |
| 67 | ipv4CidrRange: CIDR, |
| 68 | description: "alchemy-test-range", |
| 69 | labels: { env: "test" }, |
| 70 | }); |
| 71 | return { book, realm, range }; |
| 72 | }), |
| 73 | ); |
| 74 | |
| 75 | expect(created.range.customRangeId).toEqual(expect.any(String)); |
| 76 | expect(created.range.name).toEqual( |
| 77 | `projects/${project}/locations/${location}/customRanges/${created.range.customRangeId}`, |
| 78 | ); |
| 79 | expect(created.range.ipv4CidrRange).toEqual(CIDR); |
| 80 | expect(created.range.description).toEqual("alchemy-test-range"); |
| 81 | expect(created.range.labels).toMatchObject({ env: "test" }); |
| 82 | |
| 83 | const fetched = yield* cnr.getProjectsLocationsCustomRanges({ |
| 84 | name: created.range.name, |
| 85 | }); |
| 86 | expect(fetched.name).toEqual(created.range.name); |
| 87 | expect(fetched.ipv4CidrRange).toEqual(CIDR); |
| 88 | expect(fetched.labels?.env).toEqual("test"); |
| 89 | expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual( |
| 90 | true, |
| 91 | ); |
| 92 | |
| 93 | const updated = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | const book = yield* GCP.CloudNumberRegistry.RegistryBook("Inventory", { |
| 96 | registryBookId: created.book.registryBookId, |
| 97 | location, |
| 98 | labels: { env: "test" }, |
| 99 | }); |
| 100 | const realm = yield* GCP.CloudNumberRegistry.Realm("Private", { |
| 101 | realmId: created.realm.realmId, |
| 102 | location, |
| 103 | registryBook: book.name, |
| 104 | trafficType: "PRIVATE", |
| 105 | managementType: "USER", |
| 106 | ipVersion: "IPV4", |
| 107 | labels: { env: "test" }, |
| 108 | }); |
| 109 | const range = yield* GCP.CloudNumberRegistry.CustomRange("OnPrem", { |
| 110 | customRangeId: created.range.customRangeId, |
| 111 | location, |
| 112 | realm: realm.name, |
| 113 | ipv4CidrRange: CIDR, |
| 114 | description: "alchemy-prod-range", |
| 115 | attributes: [{ key: "site", value: "campus" }], |
| 116 | labels: { env: "prod", role: "range" }, |
| 117 | }); |
| 118 | return { book, realm, range }; |
| 119 | }), |
| 120 | ); |
| 121 | |
| 122 | expect(updated.range.name).toEqual(created.range.name); |
| 123 | expect(updated.range.customRangeId).toEqual(created.range.customRangeId); |
| 124 | expect(updated.range.description).toEqual("alchemy-prod-range"); |
| 125 | expect(updated.range.labels).toMatchObject({ |
| 126 | env: "prod", |
| 127 | role: "range", |
| 128 | }); |
| 129 | |
| 130 | const refetched = yield* cnr.getProjectsLocationsCustomRanges({ |
| 131 | name: created.range.name, |
| 132 | }); |
| 133 | expect(refetched.description).toEqual("alchemy-prod-range"); |
| 134 | expect(refetched.labels?.env).toEqual("prod"); |
| 135 | expect(refetched.labels?.role).toEqual("range"); |
| 136 | |
| 137 | yield* stack.destroy(); |
| 138 | const gone = yield* waitUntilGone( |
| 139 | cnr.getProjectsLocationsCustomRanges({ name: created.range.name }), |
| 140 | ); |
| 141 | expect(gone).toEqual("gone"); |
| 142 | }).pipe(logLevel), |
| 143 | { |
| 144 | tags: ["provider:gcp", "provider:gcp:cloudnumberregistry", "live"], |
| 145 | timeout: 90_000, |
| 146 | }, |
| 147 | ); |