| 1 | /** |
| 2 | * `AWS.DynamoDB.Table` under `alchemy dev`: the dualized provider deploys |
| 3 | * the table into the floci emulator, including Contributor Insights |
| 4 | * teardown (`DescribeContributorInsights` + CloudWatch `DescribeInsightRules`) |
| 5 | * on destroy. |
| 6 | * |
| 7 | * Requires Docker (floci runs as a container); skipped when unavailable. |
| 8 | */ |
| 9 | import * as AWS from "@/AWS"; |
| 10 | import * as Test from "@/Test/Alchemy"; |
| 11 | import { expect } from "alchemy-test"; |
| 12 | import * as Effect from "effect/Effect"; |
| 13 | import { |
| 14 | dockerAvailable, |
| 15 | rawAwsJson, |
| 16 | regionOfArn, |
| 17 | } from "../Local/fixtures/raw.ts"; |
| 18 | |
| 19 | const { test } = Test.make({ providers: AWS.providers(), dev: true }); |
| 20 | |
| 21 | test.provider.skipIf(!dockerAvailable)( |
| 22 | "dev table create/destroy against floci", |
| 23 | (stack) => |
| 24 | Effect.gen(function* () { |
| 25 | yield* stack.destroy(); |
| 26 | |
| 27 | const table = yield* stack.deploy( |
| 28 | AWS.DynamoDB.Table("LocalTable", { |
| 29 | partitionKey: "id", |
| 30 | attributes: { id: "S" }, |
| 31 | }), |
| 32 | ); |
| 33 | |
| 34 | expect(table.tableArn).toContain(":000000000000:"); |
| 35 | expect(table.tableArn).toContain(":us-east-1:"); |
| 36 | |
| 37 | const region = regionOfArn(table.tableArn); |
| 38 | const described = yield* rawAwsJson({ |
| 39 | service: "dynamodb", |
| 40 | region, |
| 41 | target: "DynamoDB_20120810.DescribeTable", |
| 42 | contentType: "application/x-amz-json-1.0", |
| 43 | body: { TableName: table.tableName }, |
| 44 | }); |
| 45 | expect(described.status).toBe(200); |
| 46 | |
| 47 | yield* stack.destroy(); |
| 48 | |
| 49 | const after = yield* rawAwsJson({ |
| 50 | service: "dynamodb", |
| 51 | region, |
| 52 | target: "DynamoDB_20120810.DescribeTable", |
| 53 | contentType: "application/x-amz-json-1.0", |
| 54 | body: { TableName: table.tableName }, |
| 55 | }); |
| 56 | expect(after.status).toBe(400); |
| 57 | }), |
| 58 | { |
| 59 | tags: ["provider:aws", "provider:aws:dynamodb", "local"], |
| 60 | timeout: 180_000, |
| 61 | }, |
| 62 | ); |