| 1 | import * as AWS from "@/AWS"; |
| 2 | import { OriginAccessControl } from "@/AWS/CloudFront"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as cloudfront from "@distilled.cloud/aws/cloudfront"; |
| 6 | import { describe, expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | describe( |
| 13 | "AWS.CloudFront.OriginAccessControl", |
| 14 | { tags: ["provider:aws", "provider:aws:cloudfront", "live"] }, |
| 15 | () => { |
| 16 | test.provider( |
| 17 | "list enumerates the deployed origin access control", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | const deployed = yield* stack.deploy( |
| 23 | Effect.gen(function* () { |
| 24 | return yield* OriginAccessControl("ListOriginAccessControl", { |
| 25 | description: "list", |
| 26 | originType: "s3", |
| 27 | }); |
| 28 | }), |
| 29 | ); |
| 30 | |
| 31 | const provider = yield* Provider.findProvider(OriginAccessControl); |
| 32 | const all = yield* provider.list(); |
| 33 | |
| 34 | expect( |
| 35 | all.some( |
| 36 | (o) => o.originAccessControlId === deployed.originAccessControlId, |
| 37 | ), |
| 38 | ).toBe(true); |
| 39 | |
| 40 | yield* stack.destroy(); |
| 41 | yield* assertOriginAccessControlDeleted( |
| 42 | deployed.originAccessControlId, |
| 43 | ); |
| 44 | }), |
| 45 | { timeout: 300_000 }, |
| 46 | ); |
| 47 | }, |
| 48 | ); |
| 49 | |
| 50 | const assertOriginAccessControlDeleted = (id: string) => |
| 51 | cloudfront.getOriginAccessControlConfig({ Id: id }).pipe( |
| 52 | Effect.flatMap(() => |
| 53 | Effect.fail(new Error("OriginAccessControlStillExists")), |
| 54 | ), |
| 55 | Effect.catchTag("NoSuchOriginAccessControl", () => Effect.void), |
| 56 | Effect.retry({ |
| 57 | while: (error) => |
| 58 | error instanceof Error && |
| 59 | error.message === "OriginAccessControlStillExists", |
| 60 | schedule: Schedule.max([ |
| 61 | Schedule.fixed("5 seconds"), |
| 62 | Schedule.recurs(24), |
| 63 | ]), |
| 64 | }), |
| 65 | ); |