sailfork / t3code-github / .repos/ alchemy-effect/ packages/ integration-tests/ test/ AWS/ ElastiCache/ Provisioned.Redis.test.ts

import * as AWS from "@alchemy.run/aws";
import { expect } from "@alchemy.run/test";
import * as Test from "@alchemy.run/test/Alchemy";
import * as ElastiCache from "@distilled.cloud/aws/elasticache";
import * as Effect from "effect/Effect";
import {
  assertReplicationGroupGone,
  getProvisionedNetwork,
  shareProvisionedNetwork,
} from "./ProvisionedFixture.ts";

const { test, beforeAll, afterAll } = Test.make({
  providers: AWS.providers(),
});
shareProvisionedNetwork({ beforeAll, afterAll });
test.provider.skipIf(!!process.env.FAST)(
  "create, update, verify, and destroy a provisioned Redis OSS replication group",
  (stack) =>
    Effect.gen(function* () {
      yield* stack.destroy();
      const net = yield* getProvisionedNetwork;
      const deploy = (description: string) =>
        stack.deploy(
          Effect.gen(function* () {
            const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", {
              description,
              engine: "redis",
              nodeType: "cache.t4g.micro",
              subnetGroupName: net.subnetGroupName,
              securityGroupIds: [net.securityGroupId],
              replicasPerNodeGroup: 0,
              transitEncryptionEnabled: true,
              tags: { fixture: "elasticache-provisioned-redis" },
            });
            return { cache };
          }),
        );

      const { cache } = yield* deploy("alchemy Redis OSS cache");
      const created = yield* ElastiCache.describeReplicationGroups({
        ReplicationGroupId: cache.replicationGroupId,
      });
      expect(created.ReplicationGroups?.[0]?.Engine).toBe("redis");
      expect(created.ReplicationGroups?.[0]?.Status).toBe("available");

      const { cache: updated } = yield* deploy("alchemy Redis OSS cache v2");
      expect(updated.replicationGroupId).toBe(cache.replicationGroupId);

      yield* stack.destroy();
      yield* assertReplicationGroupGone(cache.replicationGroupId);
    }),
  {
    tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"],
    timeout: 2_700_000,
  },
);