import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { semaphoreAdapterTestSuite } from "@daiso-tech/core/semaphore/test-utilities";
import { RedisSemaphoreAdapter } from "@daiso-tech/core/semaphore/adapters";
import { Redis } from "ioredis";
import {
RedisContainer,
type StartedRedisContainer,
} from "@testcontainers/redis";
import { TimeSpan } from "@daiso-tech/core/utilities";
const timeout = TimeSpan.fromMinutes(2);
describe("class: RedisSemaphoreAdapter", () => {
let client: Redis;
let startedContainer: StartedRedisContainer;
beforeEach(async () => {
startedContainer = await new RedisContainer("redis:7.4.2").start();
client = new Redis(startedContainer.getConnectionUrl());
}, timeout.toMilliseconds());
afterEach(async () => {
await client.quit();
await startedContainer.stop();
}, timeout.toMilliseconds());
semaphoreAdapterTestSuite({
createAdapter: () =>
new RedisSemaphoreAdapter(client),
test,
beforeEach,
expect,
describe,
});
});
The
semaphoreAdapterTestSuite
function simplifies the process of testing your custom implementation ofISemaphoreAdapter
withvitest
.IMPORT_PATH:
"@daiso-tech/core/semaphore/test-utilities"