1import * as AWS from "@/AWS";
2import { Connection } from "@/AWS/Glue";
3import * as Test from "@/Test/Alchemy";
4import * as glue from "@distilled.cloud/aws/glue";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7import * as Redacted from "effect/Redacted";
8
9const { test } = Test.make({ providers: AWS.providers() });
10
11const getConnection = (name: string) =>
12 glue.getConnection({ Name: name, HidePassword: true }).pipe(
13 Effect.map((r) => r.Connection),
14 Effect.catchTag("EntityNotFoundException", () => Effect.succeed(undefined)),
15 );
16
17test.provider(
18 "create, update, delete Glue JDBC connection",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22
23 const created = yield* stack.deploy(
24 Effect.gen(function* () {
25 return yield* Connection("Warehouse", {
26 connectionType: "JDBC",
27 description: "warehouse jdbc",
28 connectionProperties: {
29 JDBC_CONNECTION_URL:
30 "jdbc:postgresql://db.example.com:5432/warehouse",
31 USERNAME: "glue",
32 PASSWORD: Redacted.make("secret"),
33 },
34 tags: { Environment: "test" },
35 });
36 }),
37 );
38
39 expect(created.connectionName).toBeDefined();
40 expect(created.connectionType).toEqual("JDBC");
41 expect(created.connectionArn).toContain(
42 `:connection/${created.connectionName}`,
43 );
44
45 const observed = yield* getConnection(created.connectionName);
46 expect(observed?.Name).toEqual(created.connectionName);
47 expect(observed?.ConnectionType).toEqual("JDBC");
48 expect(observed?.ConnectionProperties?.JDBC_CONNECTION_URL).toEqual(
49 "jdbc:postgresql://db.example.com:5432/warehouse",
50 );
51
52 const tags = yield* glue.getTags({ ResourceArn: created.connectionArn });
53 expect(tags.Tags?.["alchemy::id"]).toBeDefined();
54 expect(tags.Tags?.Environment).toEqual("test");
55
56 // update the JDBC URL
57 yield* stack.deploy(
58 Effect.gen(function* () {
59 return yield* Connection("Warehouse", {
60 connectionType: "JDBC",
61 description: "warehouse jdbc v2",
62 connectionProperties: {
63 JDBC_CONNECTION_URL:
64 "jdbc:postgresql://db2.example.com:5432/warehouse",
65 USERNAME: "glue",
66 PASSWORD: Redacted.make("secret"),
67 },
68 tags: { Environment: "test" },
69 });
70 }),
71 );
72
73 const reobserved = yield* getConnection(created.connectionName);
74 expect(reobserved?.ConnectionProperties?.JDBC_CONNECTION_URL).toEqual(
75 "jdbc:postgresql://db2.example.com:5432/warehouse",
76 );
77
78 yield* stack.destroy();
79 const gone = yield* getConnection(created.connectionName);
80 expect(gone).toBeUndefined();
81 }),
82 { tags: ["provider:aws", "provider:aws:glue", "live"] },
83);