1import * as AWS from "@/AWS";
2import { KeyValueStore } from "@/AWS/CloudFront";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import * as cloudfront from "@distilled.cloud/aws/cloudfront";
6import { describe, expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8import * as Schedule from "effect/Schedule";
9
10const { test } = Test.make({ providers: AWS.providers() });
11
12describe(
13 "AWS.CloudFront.KeyValueStore",
14 { tags: ["provider:aws", "provider:aws:cloudfront", "live"] },
15 () => {
16 test.provider(
17 "list enumerates the deployed key value store",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const deployed = yield* stack.deploy(
23 Effect.gen(function* () {
24 return yield* KeyValueStore("ListKeyValueStore", {
25 comment: "list",
26 });
27 }),
28 );
29
30 const provider = yield* Provider.findProvider(KeyValueStore);
31 const all = yield* provider.list();
32
33 expect(
34 all.some((s) => s.keyValueStoreId === deployed.keyValueStoreId),
35 ).toBe(true);
36
37 yield* stack.destroy();
38 yield* assertKeyValueStoreDeleted(deployed.keyValueStoreName);
39 }),
40 { timeout: 300_000 },
41 );
42 },
43);
44
45const assertKeyValueStoreDeleted = (name: string) =>
46 cloudfront.describeKeyValueStore({ Name: name }).pipe(
47 Effect.flatMap(() => Effect.fail(new Error("KeyValueStoreStillExists"))),
48 Effect.catchTag("EntityNotFound", () => Effect.void),
49 Effect.retry({
50 while: (error) =>
51 error instanceof Error && error.message === "KeyValueStoreStillExists",
52 schedule: Schedule.max([
53 Schedule.fixed("5 seconds"),
54 Schedule.recurs(24),
55 ]),
56 }),
57 );