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 saasservicemgmt from "@distilled.cloud/gcp/saasservicemgmt_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { location, logLevel, currentProject, runLifecycle, waitUntilGone } from "./common.ts"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: GCP.providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "getProjectsLocationsUnitKinds on a missing unit kind fails with a typed tag", |
| 12 | (stack) => |
| 13 | Effect.gen(function* () { |
| 14 | const project = yield* currentProject; |
| 15 | yield* stack.destroy(); |
| 16 | |
| 17 | const error = yield* Effect.flip( |
| 18 | saasservicemgmt.getProjectsLocationsUnitKinds({ |
| 19 | name: `projects/${project}/locations/${location}/unitKinds/alchemy-missing-uk`, |
| 20 | }), |
| 21 | ); |
| 22 | expect(error._tag).toEqual("NotFound"); |
| 23 | |
| 24 | yield* stack.destroy(); |
| 25 | }).pipe(logLevel), |
| 26 | { |
| 27 | tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"], |
| 28 | timeout: 90_000, |
| 29 | }, |
| 30 | ); |
| 31 | |
| 32 | test.provider.skipIf(!runLifecycle)( |
| 33 | "create, update, and delete a unit kind", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const created = yield* stack.deploy( |
| 39 | Effect.gen(function* () { |
| 40 | const product = yield* GCP.SaasServiceManagement.Saa("Inventory", { |
| 41 | location, |
| 42 | locations: [{ name: location }], |
| 43 | }); |
| 44 | const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", { |
| 45 | location, |
| 46 | saas: product.name, |
| 47 | labels: { env: "test" }, |
| 48 | }); |
| 49 | return { product, kind }; |
| 50 | }), |
| 51 | ); |
| 52 | |
| 53 | expect(created.kind.name).toContain("/unitKinds/"); |
| 54 | expect(created.kind.saasId).toEqual(created.product.saasId); |
| 55 | expect(created.kind.labels).toMatchObject({ env: "test" }); |
| 56 | |
| 57 | const fetched = yield* saasservicemgmt.getProjectsLocationsUnitKinds({ |
| 58 | name: created.kind.name, |
| 59 | }); |
| 60 | expect(fetched.name).toEqual(created.kind.name); |
| 61 | expect(fetched.labels?.env).toEqual("test"); |
| 62 | expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual( |
| 63 | true, |
| 64 | ); |
| 65 | |
| 66 | const updated = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | const product = yield* GCP.SaasServiceManagement.Saa("Inventory", { |
| 69 | saasId: created.product.saasId, |
| 70 | location, |
| 71 | locations: [{ name: location }], |
| 72 | }); |
| 73 | const kind = yield* GCP.SaasServiceManagement.UnitKind("Store", { |
| 74 | unitKindId: created.kind.unitKindId, |
| 75 | location, |
| 76 | saas: product.name, |
| 77 | labels: { env: "prod", role: "kind" }, |
| 78 | }); |
| 79 | return { product, kind }; |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | expect(updated.kind.name).toEqual(created.kind.name); |
| 84 | expect(updated.kind.labels).toMatchObject({ env: "prod", role: "kind" }); |
| 85 | |
| 86 | yield* stack.destroy(); |
| 87 | const gone = yield* waitUntilGone( |
| 88 | saasservicemgmt.getProjectsLocationsUnitKinds({ |
| 89 | name: created.kind.name, |
| 90 | }), |
| 91 | ); |
| 92 | expect(gone).toEqual("gone"); |
| 93 | }).pipe(logLevel), |
| 94 | { |
| 95 | tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"], |
| 96 | timeout: 90_000, |
| 97 | }, |
| 98 | ); |