1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as datastream from "@distilled.cloud/gcp/datastream_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import {
7 LOCATION,
8 logLevel,
9 currentProject,
10 runLifecycle,
11 waitUntilGone,
12} from "./common.ts";
13
14const { test } = Test.make({ providers: GCP.providers() });
15
16test.provider(
17 "getProjectsLocationsConnectionProfiles on a missing profile fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 const project = yield* currentProject;
21 yield* stack.destroy();
22
23 const error = yield* Effect.flip(
24 datastream.getProjectsLocationsConnectionProfiles({
25 name: `projects/${project}/locations/${LOCATION}/connectionProfiles/alchemy-missing-profile`,
26 }),
27 );
28 expect(error._tag).toEqual("NotFound");
29
30 yield* stack.destroy();
31 }).pipe(logLevel),
32 {
33 tags: ["provider:gcp", "provider:gcp:datastream", "live"],
34 timeout: 90_000,
35 },
36);
37
38test.provider.skipIf(!runLifecycle)(
39 "create, update, and delete a bigquery connection profile",
40 (stack) =>
41 Effect.gen(function* () {
42 const project = yield* currentProject;
43 yield* stack.destroy();
44
45 const created = yield* stack.deploy(
46 Effect.gen(function* () {
47 return yield* GCP.Datastream.ConnectionProfile("BqDest", {
48 location: LOCATION,
49 displayName: "bq-dest",
50 labels: { env: "test" },
51 bigqueryProfile: {},
52 });
53 }),
54 );
55
56 expect(created.connectionProfileId).toEqual(expect.any(String));
57 expect(created.name).toEqual(
58 `projects/${project}/locations/${LOCATION}/connectionProfiles/${created.connectionProfileId}`,
59 );
60 expect(created.location).toEqual(LOCATION);
61 expect(created.displayName).toEqual("bq-dest");
62 expect(created.labels).toMatchObject({ env: "test" });
63 expect(created.bigqueryProfile).toEqual({});
64
65 const fetched = yield* datastream.getProjectsLocationsConnectionProfiles({
66 name: created.name,
67 });
68 expect(fetched.name).toEqual(created.name);
69 expect(fetched.displayName).toEqual("bq-dest");
70 expect(fetched.labels?.env).toEqual("test");
71
72 const updated = yield* stack.deploy(
73 Effect.gen(function* () {
74 return yield* GCP.Datastream.ConnectionProfile("BqDest", {
75 connectionProfileId: created.connectionProfileId,
76 location: LOCATION,
77 displayName: "bq-dest-v2",
78 labels: { env: "prod", team: "datastream" },
79 bigqueryProfile: {},
80 });
81 }),
82 );
83
84 expect(updated.name).toEqual(created.name);
85 expect(updated.displayName).toEqual("bq-dest-v2");
86 expect(updated.labels).toMatchObject({ env: "prod", team: "datastream" });
87
88 const fetchedUpdate =
89 yield* datastream.getProjectsLocationsConnectionProfiles({
90 name: updated.name,
91 });
92 expect(fetchedUpdate.displayName).toEqual("bq-dest-v2");
93 expect(fetchedUpdate.labels?.team).toEqual("datastream");
94
95 yield* stack.destroy();
96 const gone = yield* waitUntilGone(
97 datastream.getProjectsLocationsConnectionProfiles({
98 name: created.name,
99 }),
100 );
101 expect(gone).toEqual("gone");
102 }).pipe(logLevel),
103 {
104 tags: ["provider:gcp", "provider:gcp:datastream", "live"],
105 timeout: 300_000,
106 },
107);