| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Database } from "@/AWS/Glue"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as glue from "@distilled.cloud/aws/glue"; |
| 5 | import { expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | const getDatabase = (name: string) => |
| 11 | glue.getDatabase({ Name: name }).pipe( |
| 12 | Effect.map((r) => r.Database), |
| 13 | Effect.catchTag("EntityNotFoundException", () => Effect.succeed(undefined)), |
| 14 | ); |
| 15 | |
| 16 | test.provider( |
| 17 | "create, update, delete Glue database", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | // create |
| 23 | const created = yield* stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | return yield* Database("AnalyticsDb", { |
| 26 | description: "analytics tables", |
| 27 | parameters: { classification: "parquet" }, |
| 28 | }); |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | expect(created.databaseName).toBeDefined(); |
| 33 | expect(created.databaseArn).toContain( |
| 34 | `:database/${created.databaseName}`, |
| 35 | ); |
| 36 | expect(created.catalogId).toBeDefined(); |
| 37 | |
| 38 | // out-of-band verification |
| 39 | const observed = yield* getDatabase(created.databaseName); |
| 40 | expect(observed?.Name).toEqual(created.databaseName); |
| 41 | expect(observed?.Description).toEqual("analytics tables"); |
| 42 | expect(observed?.Parameters?.classification).toEqual("parquet"); |
| 43 | // ownership markers live in the Parameters map (databases aren't taggable) |
| 44 | expect(observed?.Parameters?.["alchemy::id"]).toBeDefined(); |
| 45 | |
| 46 | // update: description + parameters |
| 47 | const updated = yield* stack.deploy( |
| 48 | Effect.gen(function* () { |
| 49 | return yield* Database("AnalyticsDb", { |
| 50 | description: "curated analytics tables", |
| 51 | locationUri: "s3://example-bucket/analytics/", |
| 52 | parameters: { classification: "json" }, |
| 53 | }); |
| 54 | }), |
| 55 | ); |
| 56 | |
| 57 | expect(updated.databaseName).toEqual(created.databaseName); |
| 58 | const reobserved = yield* getDatabase(created.databaseName); |
| 59 | expect(reobserved?.Description).toEqual("curated analytics tables"); |
| 60 | expect(reobserved?.LocationUri).toEqual("s3://example-bucket/analytics/"); |
| 61 | expect(reobserved?.Parameters?.classification).toEqual("json"); |
| 62 | |
| 63 | // delete |
| 64 | yield* stack.destroy(); |
| 65 | const gone = yield* getDatabase(created.databaseName); |
| 66 | expect(gone).toBeUndefined(); |
| 67 | }), |
| 68 | { tags: ["provider:aws", "provider:aws:glue", "live"] }, |
| 69 | ); |