@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, 04:45 UTC

main
ts 98 lines 3.49 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { SubnetGroup } from "@alchemy.run/aws/MemoryDB";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as EC2 from "@distilled.cloud/aws/ec2";
6 import * as memorydb from "@distilled.cloud/aws/memorydb";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import { getDefaultVpc } from "../DefaultVpc.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Resolve two default-for-AZ subnets from the account's default VPC.
14 const defaultSubnetIds = Effect.gen(function* () {
15 const vpc = yield* getDefaultVpc;
16 const subnets = yield* EC2.describeSubnets({
17 Filters: [
18 { Name: "vpc-id", Values: [vpc.vpcId] },
19 { Name: "default-for-az", Values: ["true"] },
20 ],
21 });
22 const ids = (subnets.Subnets ?? [])
23 .map((s) => s.SubnetId)
24 .filter((id): id is string => id !== undefined)
25 .sort();
26 if (ids.length < 2) {
27 return yield* Effect.die(new Error("default VPC has fewer than 2 default-for-AZ subnets"));
28 }
29 return ids;
30 });
31
32 const assertGone = (name: string) =>
33 memorydb.describeSubnetGroups({ SubnetGroupName: name }).pipe(
34 Effect.flatMap(() => Effect.fail(new Error(`subnet group '${name}' still exists`))),
35 Effect.catchTag("SubnetGroupNotFoundFault", () => Effect.void),
36 Effect.retry({
37 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
38 }),
39 );
40
41 test.provider(
42 "create, update description, delete a MemoryDB subnet group",
43 (stack) =>
44 Effect.gen(function* () {
45 yield* stack.destroy();
46
47 const subnetIds = yield* defaultSubnetIds;
48
49 const { group } = yield* stack.deploy(
50 Effect.gen(function* () {
51 const group = yield* SubnetGroup("Subnets", {
52 description: "alchemy memorydb subnet group",
53 subnetIds: subnetIds.slice(0, 2),
54 tags: { fixture: "memorydb-subnet-group" },
55 });
56 return { group };
57 }),
58 );
59
60 expect(group.subnetGroupName).toBeDefined();
61 expect(group.subnetGroupArn).toContain(":subnetgroup/");
62 expect(new Set(group.subnetIds)).toEqual(new Set(subnetIds.slice(0, 2)));
63
64 // Out-of-band verification.
65 const described = yield* memorydb.describeSubnetGroups({
66 SubnetGroupName: group.subnetGroupName,
67 });
68 const observed = described.SubnetGroups?.[0];
69 expect(observed?.Description).toBe("alchemy memorydb subnet group");
70 expect(observed?.VpcId).toBeDefined();
71
72 // Update the description in place (name unchanged).
73 const { group: updated } = yield* stack.deploy(
74 Effect.gen(function* () {
75 const group = yield* SubnetGroup("Subnets", {
76 description: "alchemy memorydb subnet group v2",
77 subnetIds: subnetIds.slice(0, 2),
78 tags: { fixture: "memorydb-subnet-group", env: "test" },
79 });
80 return { group };
81 }),
82 );
83 expect(updated.subnetGroupName).toBe(group.subnetGroupName);
84 expect(updated.description).toBe("alchemy memorydb subnet group v2");
85
86 const redescribed = yield* memorydb.describeSubnetGroups({
87 SubnetGroupName: group.subnetGroupName,
88 });
89 expect(redescribed.SubnetGroups?.[0]?.Description).toBe("alchemy memorydb subnet group v2");
90
91 yield* stack.destroy();
92 yield* assertGone(group.subnetGroupName);
93 }),
94 {
95 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:memorydb", "live"],
96 timeout: 240_000,
97 },
98 );