@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 75 lines 3.07 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { LogGroup } from "@alchemy.run/aws/Logs";
3 import { AccessLogSubscription, ServiceNetwork } from "@alchemy.run/aws/VpcLattice";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as vpclattice from "@distilled.cloud/aws/vpc-lattice";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // CloudWatch log-group destination ARNs round-trip through the lattice API
12 // with a trailing `:*`.
13 const normalizeArn = (arn: string) => arn.replace(/:\*$/, "");
14
15 test.provider(
16 "create, update destination, delete an access log subscription",
17 (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 const program = (destination: "primary" | "secondary") =>
22 Effect.gen(function* () {
23 const network = yield* ServiceNetwork("LogsNetwork", {});
24 const primary = yield* LogGroup("LatticeLogsPrimary", {
25 retention: "1 days",
26 });
27 const secondary = yield* LogGroup("LatticeLogsSecondary", {
28 retention: "1 days",
29 });
30 const subscription = yield* AccessLogSubscription("NetworkLogs", {
31 resourceIdentifier: network.serviceNetworkId,
32 destinationArn: destination === "primary" ? primary.logGroupArn : secondary.logGroupArn,
33 });
34 return { network, primary, secondary, subscription };
35 });
36
37 const first = yield* stack.deploy(program("primary"));
38
39 expect(first.subscription.accessLogSubscriptionId).toMatch(/^als-/);
40 expect(normalizeArn(first.subscription.destinationArn)).toBe(
41 normalizeArn(first.primary.logGroupArn),
42 );
43
44 const live = yield* vpclattice.getAccessLogSubscription({
45 accessLogSubscriptionIdentifier: first.subscription.accessLogSubscriptionId,
46 });
47 expect(normalizeArn(live.destinationArn)).toBe(normalizeArn(first.primary.logGroupArn));
48 expect(live.resourceId).toBe(first.network.serviceNetworkId);
49
50 // Update the destination in place (same destination type).
51 const second = yield* stack.deploy(program("secondary"));
52 expect(second.subscription.accessLogSubscriptionId).toBe(
53 first.subscription.accessLogSubscriptionId,
54 );
55 const updated = yield* vpclattice.getAccessLogSubscription({
56 accessLogSubscriptionIdentifier: first.subscription.accessLogSubscriptionId,
57 });
58 expect(normalizeArn(updated.destinationArn)).toBe(normalizeArn(first.secondary.logGroupArn));
59
60 yield* stack.destroy();
61 const gone = yield* vpclattice
62 .getAccessLogSubscription({
63 accessLogSubscriptionIdentifier: first.subscription.accessLogSubscriptionId,
64 })
65 .pipe(
66 Effect.map(() => false),
67 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
68 );
69 expect(gone).toBe(true);
70 }).pipe(Effect.ensuring(Effect.ignore(stack.destroy()))),
71 {
72 tags: ["provider:aws", "provider:aws:logs", "provider:aws:vpclattice", "live"],
73 timeout: 300_000,
74 },
75 );