mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-10-17 07:47:44 +02:00
108 lines
3.5 KiB
TypeScript
108 lines
3.5 KiB
TypeScript
import * as AWS from "@/AWS";
|
|
import { DBSubnetGroup } from "@/AWS/Neptune";
|
|
import * as Test from "@/Test/Alchemy";
|
|
import * as EC2 from "@distilled.cloud/aws/ec2";
|
|
import * as neptune from "@distilled.cloud/aws/neptune";
|
|
import { expect } from "alchemy-test";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Schedule from "effect/Schedule";
|
|
import { getDefaultVpc } from "../DefaultVpc.ts";
|
|
|
|
const { test } = Test.make({ providers: AWS.providers() });
|
|
|
|
// Resolve two default-for-AZ subnets from the account's default VPC.
|
|
const defaultSubnetIds = Effect.gen(function* () {
|
|
const vpc = yield* getDefaultVpc;
|
|
const subnets = yield* EC2.describeSubnets({
|
|
Filters: [
|
|
{ Name: "vpc-id", Values: [vpc.vpcId] },
|
|
{ Name: "default-for-az", Values: ["true"] },
|
|
],
|
|
});
|
|
const ids = (subnets.Subnets ?? [])
|
|
.map((s) => s.SubnetId)
|
|
.filter((id): id is `subnet-${string}` => id !== undefined)
|
|
.sort();
|
|
if (ids.length < 2) {
|
|
return yield* Effect.die(
|
|
new Error("default VPC has fewer than 2 default-for-AZ subnets"),
|
|
);
|
|
}
|
|
return ids;
|
|
});
|
|
|
|
const assertGone = (name: string) =>
|
|
neptune.describeDBSubnetGroups({ DBSubnetGroupName: name }).pipe(
|
|
Effect.flatMap(() =>
|
|
Effect.fail(new Error(`subnet group '${name}' still exists`)),
|
|
),
|
|
Effect.catchTag("DBSubnetGroupNotFoundFault", () => Effect.void),
|
|
Effect.retry({
|
|
schedule: Schedule.max([
|
|
Schedule.fixed("2 seconds"),
|
|
Schedule.recurs(10),
|
|
]),
|
|
}),
|
|
);
|
|
|
|
test.provider(
|
|
"create, update description, delete a Neptune DB subnet group",
|
|
(stack) =>
|
|
Effect.gen(function* () {
|
|
yield* stack.destroy();
|
|
|
|
const subnetIds = yield* defaultSubnetIds;
|
|
|
|
const { group } = yield* stack.deploy(
|
|
Effect.gen(function* () {
|
|
const group = yield* DBSubnetGroup("Subnets", {
|
|
description: "alchemy neptune subnet group",
|
|
subnetIds: subnetIds.slice(0, 2),
|
|
tags: { fixture: "neptune-subnet-group" },
|
|
});
|
|
return { group };
|
|
}),
|
|
);
|
|
|
|
expect(group.dbSubnetGroupName).toBeDefined();
|
|
expect(group.dbSubnetGroupArn).toContain(":subgrp:");
|
|
expect(new Set(group.subnetIds)).toEqual(new Set(subnetIds.slice(0, 2)));
|
|
|
|
// Out-of-band verification.
|
|
const described = yield* neptune.describeDBSubnetGroups({
|
|
DBSubnetGroupName: group.dbSubnetGroupName,
|
|
});
|
|
const observed = described.DBSubnetGroups?.[0];
|
|
expect(observed?.DBSubnetGroupDescription).toBe(
|
|
"alchemy neptune subnet group",
|
|
);
|
|
expect(observed?.VpcId).toBeDefined();
|
|
|
|
// Update the description in place (name unchanged).
|
|
const { group: updated } = yield* stack.deploy(
|
|
Effect.gen(function* () {
|
|
const group = yield* DBSubnetGroup("Subnets", {
|
|
description: "alchemy neptune subnet group v2",
|
|
subnetIds: subnetIds.slice(0, 2),
|
|
tags: { fixture: "neptune-subnet-group", env: "test" },
|
|
});
|
|
return { group };
|
|
}),
|
|
);
|
|
expect(updated.dbSubnetGroupName).toBe(group.dbSubnetGroupName);
|
|
|
|
const redescribed = yield* neptune.describeDBSubnetGroups({
|
|
DBSubnetGroupName: group.dbSubnetGroupName,
|
|
});
|
|
expect(redescribed.DBSubnetGroups?.[0]?.DBSubnetGroupDescription).toBe(
|
|
"alchemy neptune subnet group v2",
|
|
);
|
|
|
|
yield* stack.destroy();
|
|
yield* assertGone(group.dbSubnetGroupName);
|
|
}),
|
|
{
|
|
tags: ["provider:aws", "provider:aws:ec2", "provider:aws:neptune", "live"],
|
|
timeout: 240_000,
|
|
},
|
|
);
|