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