t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/VpcLattice/AccessLogSubscription.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

92 lines
3.2 KiB
TypeScript

import * as AWS from "@/AWS";
import { LogGroup } from "@/AWS/Logs";
import { AccessLogSubscription, ServiceNetwork } from "@/AWS/VpcLattice";
import * as Test from "@/Test/Alchemy";
import * as vpclattice from "@distilled.cloud/aws/vpc-lattice";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
// CloudWatch log-group destination ARNs round-trip through the lattice API
// with a trailing `:*`.
const normalizeArn = (arn: string) => arn.replace(/:\*$/, "");
test.provider(
"create, update destination, delete an access log subscription",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const program = (destination: "primary" | "secondary") =>
Effect.gen(function* () {
const network = yield* ServiceNetwork("LogsNetwork", {});
const primary = yield* LogGroup("LatticeLogsPrimary", {
retention: "1 days",
});
const secondary = yield* LogGroup("LatticeLogsSecondary", {
retention: "1 days",
});
const subscription = yield* AccessLogSubscription("NetworkLogs", {
resourceIdentifier: network.serviceNetworkId,
destinationArn:
destination === "primary"
? primary.logGroupArn
: secondary.logGroupArn,
});
return { network, primary, secondary, subscription };
});
const first = yield* stack.deploy(program("primary"));
expect(first.subscription.accessLogSubscriptionId).toMatch(/^als-/);
expect(normalizeArn(first.subscription.destinationArn)).toBe(
normalizeArn(first.primary.logGroupArn),
);
const live = yield* vpclattice.getAccessLogSubscription({
accessLogSubscriptionIdentifier:
first.subscription.accessLogSubscriptionId,
});
expect(normalizeArn(live.destinationArn)).toBe(
normalizeArn(first.primary.logGroupArn),
);
expect(live.resourceId).toBe(first.network.serviceNetworkId);
// Update the destination in place (same destination type).
const second = yield* stack.deploy(program("secondary"));
expect(second.subscription.accessLogSubscriptionId).toBe(
first.subscription.accessLogSubscriptionId,
);
const updated = yield* vpclattice.getAccessLogSubscription({
accessLogSubscriptionIdentifier:
first.subscription.accessLogSubscriptionId,
});
expect(normalizeArn(updated.destinationArn)).toBe(
normalizeArn(first.secondary.logGroupArn),
);
yield* stack.destroy();
const gone = yield* vpclattice
.getAccessLogSubscription({
accessLogSubscriptionIdentifier:
first.subscription.accessLogSubscriptionId,
})
.pipe(
Effect.map(() => false),
Effect.catchTag("ResourceNotFoundException", () =>
Effect.succeed(true),
),
);
expect(gone).toBe(true);
}).pipe(Effect.ensuring(Effect.ignore(stack.destroy()))),
{
tags: [
"provider:aws",
"provider:aws:logs",
"provider:aws:vpclattice",
"live",
],
timeout: 300_000,
},
);