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 { LOCATION, logLevel, currentProject, runLifecycle, waitUntilGone } from "./common.ts"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: GCP.providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "getProjectsLocationsStreams on a missing stream 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 | datastream.getProjectsLocationsStreams({ |
| 19 | name: `projects/${project}/locations/${LOCATION}/streams/alchemy-missing-stream`, |
| 20 | }), |
| 21 | ); |
| 22 | expect(error._tag).toEqual("NotFound"); |
| 23 | |
| 24 | yield* stack.destroy(); |
| 25 | }).pipe(logLevel), |
| 26 | { |
| 27 | tags: ["provider:gcp", "provider:gcp:datastream", "live"], |
| 28 | timeout: 90_000, |
| 29 | }, |
| 30 | ); |
| 31 | |
| 32 | test.provider.skipIf(!runLifecycle)( |
| 33 | "create and delete a mysql-to-bigquery stream", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const project = yield* currentProject; |
| 37 | yield* stack.destroy(); |
| 38 | |
| 39 | const created = yield* stack.deploy( |
| 40 | Effect.gen(function* () { |
| 41 | const source = yield* GCP.Datastream.ConnectionProfile("MysqlSrc", { |
| 42 | location: LOCATION, |
| 43 | displayName: "mysql-src", |
| 44 | mysqlProfile: { |
| 45 | hostname: "10.0.0.8", |
| 46 | port: 3306, |
| 47 | username: "alchemy", |
| 48 | password: "AlchemyTestPass1", |
| 49 | }, |
| 50 | staticServiceIpConnectivity: {}, |
| 51 | force: true, |
| 52 | }); |
| 53 | const dest = yield* GCP.Datastream.ConnectionProfile("BqDest", { |
| 54 | location: LOCATION, |
| 55 | displayName: "bq-dest", |
| 56 | bigqueryProfile: {}, |
| 57 | }); |
| 58 | const stream = yield* GCP.Datastream.Stream("MysqlToBq", { |
| 59 | location: LOCATION, |
| 60 | displayName: "mysql-to-bq", |
| 61 | labels: { env: "test" }, |
| 62 | sourceConfig: { |
| 63 | sourceConnectionProfile: source.name, |
| 64 | mysqlSourceConfig: { |
| 65 | includeObjects: { |
| 66 | mysqlDatabases: [{ database: "alchemy" }], |
| 67 | }, |
| 68 | }, |
| 69 | }, |
| 70 | destinationConfig: { |
| 71 | destinationConnectionProfile: dest.name, |
| 72 | bigqueryDestinationConfig: { |
| 73 | singleTargetDataset: { |
| 74 | datasetId: `${project}:alchemy_ds`, |
| 75 | }, |
| 76 | dataFreshness: "900s", |
| 77 | }, |
| 78 | }, |
| 79 | backfillNone: {}, |
| 80 | force: true, |
| 81 | }); |
| 82 | return { source, dest, stream }; |
| 83 | }), |
| 84 | ); |
| 85 | |
| 86 | expect(created.stream.streamId).toEqual(expect.any(String)); |
| 87 | expect(created.stream.name).toEqual( |
| 88 | `projects/${project}/locations/${LOCATION}/streams/${created.stream.streamId}`, |
| 89 | ); |
| 90 | expect(created.stream.location).toEqual(LOCATION); |
| 91 | expect(created.stream.displayName).toEqual("mysql-to-bq"); |
| 92 | expect(created.stream.labels).toMatchObject({ env: "test" }); |
| 93 | expect(created.stream.sourceConfig?.sourceConnectionProfile).toContain( |
| 94 | created.source.connectionProfileId, |
| 95 | ); |
| 96 | expect(created.stream.destinationConfig?.destinationConnectionProfile).toContain( |
| 97 | created.dest.connectionProfileId, |
| 98 | ); |
| 99 | |
| 100 | const fetched = yield* datastream.getProjectsLocationsStreams({ |
| 101 | name: created.stream.name, |
| 102 | }); |
| 103 | expect(fetched.name).toEqual(created.stream.name); |
| 104 | expect(fetched.displayName).toEqual("mysql-to-bq"); |
| 105 | expect(fetched.labels?.env).toEqual("test"); |
| 106 | |
| 107 | yield* stack.destroy(); |
| 108 | const gone = yield* waitUntilGone( |
| 109 | datastream.getProjectsLocationsStreams({ |
| 110 | name: created.stream.name, |
| 111 | }), |
| 112 | ); |
| 113 | expect(gone).toEqual("gone"); |
| 114 | }).pipe(logLevel), |
| 115 | { |
| 116 | tags: ["provider:gcp", "provider:gcp:datastream", "live"], |
| 117 | timeout: 600_000, |
| 118 | }, |
| 119 | ); |