The best way to control Claude Code, Codex and more from any computer or phone
| 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 datastream from "@distilled.cloud/gcp/datastream_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { withNetworkSlot } from "../networkQuota.ts"; |
| 7 | import { LOCATION, logLevel, currentProject, runSlowLifecycle, waitUntilGone } from "./common.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | test.provider( |
| 12 | "getProjectsLocationsPrivateConnections on a missing connection fails with a typed tag", |
| 13 | (stack) => |
| 14 | Effect.gen(function* () { |
| 15 | const project = yield* currentProject; |
| 16 | yield* stack.destroy(); |
| 17 | |
| 18 | const error = yield* Effect.flip( |
| 19 | datastream.getProjectsLocationsPrivateConnections({ |
| 20 | name: `projects/${project}/locations/${LOCATION}/privateConnections/alchemy-missing-pconn`, |
| 21 | }), |
| 22 | ); |
| 23 | expect(error._tag).toEqual("NotFound"); |
| 24 | |
| 25 | yield* stack.destroy(); |
| 26 | }).pipe(logLevel), |
| 27 | { |
| 28 | tags: ["provider:gcp", "provider:gcp:datastream", "live"], |
| 29 | timeout: 90_000, |
| 30 | }, |
| 31 | ); |
| 32 | |
| 33 | test.provider.skipIf(!runSlowLifecycle)( |
| 34 | "create and delete a private connection", |
| 35 | (stack) => |
| 36 | Effect.gen(function* () { |
| 37 | const project = yield* currentProject; |
| 38 | yield* stack.destroy(); |
| 39 | |
| 40 | const created = yield* stack.deploy( |
| 41 | Effect.gen(function* () { |
| 42 | const network = yield* GCP.Compute.Network("DsVpc", { |
| 43 | autoCreateSubnetworks: false, |
| 44 | }); |
| 45 | const peering = yield* GCP.Datastream.PrivateConnection("DsPeer", { |
| 46 | location: LOCATION, |
| 47 | displayName: "ds-peer", |
| 48 | labels: { env: "test" }, |
| 49 | force: true, |
| 50 | vpcPeeringConfig: { |
| 51 | vpc: network.networkName, |
| 52 | subnet: "10.9.0.0/29", |
| 53 | }, |
| 54 | }); |
| 55 | return { network, peering }; |
| 56 | }), |
| 57 | ); |
| 58 | |
| 59 | expect(created.peering.privateConnectionId).toEqual(expect.any(String)); |
| 60 | expect(created.peering.name).toEqual( |
| 61 | `projects/${project}/locations/${LOCATION}/privateConnections/${created.peering.privateConnectionId}`, |
| 62 | ); |
| 63 | expect(created.peering.location).toEqual(LOCATION); |
| 64 | expect(created.peering.displayName).toEqual("ds-peer"); |
| 65 | expect(created.peering.labels).toMatchObject({ env: "test" }); |
| 66 | expect(created.peering.vpcPeeringConfig?.subnet).toEqual("10.9.0.0/29"); |
| 67 | |
| 68 | const fetched = yield* datastream.getProjectsLocationsPrivateConnections({ |
| 69 | name: created.peering.name, |
| 70 | }); |
| 71 | expect(fetched.name).toEqual(created.peering.name); |
| 72 | expect(fetched.displayName).toEqual("ds-peer"); |
| 73 | expect(fetched.labels?.env).toEqual("test"); |
| 74 | expect(fetched.vpcPeeringConfig?.subnet).toEqual("10.9.0.0/29"); |
| 75 | |
| 76 | yield* stack.destroy(); |
| 77 | const gone = yield* waitUntilGone( |
| 78 | datastream.getProjectsLocationsPrivateConnections({ |
| 79 | name: created.peering.name, |
| 80 | }), |
| 81 | ); |
| 82 | expect(gone).toEqual("gone"); |
| 83 | }).pipe(logLevel, withNetworkSlot), |
| 84 | { |
| 85 | tags: ["provider:gcp", "provider:gcp:datastream", "live"], |
| 86 | timeout: 900_000, |
| 87 | }, |
| 88 | ); |