import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { sharedLockAdapterTestSuite } from "@daiso-tech/core/shared-lock/test-utilities";
import { RedisSharedLockAdapter } from "@daiso-tech/core/shared-lock/redis-shared-lock-adapter";
import { Redis } from "ioredis";
import {
RedisContainer,
type StartedRedisContainer,
} from "@testcontainers/redis";
import { TimeSpan } from "@daiso-tech/core/time-span" from "@daiso-tech/core/time-span";
const timeout = TimeSpan.fromMinutes(2);
describe("class: RedisSharedLockAdapter", () => {
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());
sharedLockAdapterTestSuite({
createAdapter: () =>
new RedisSharedLockAdapter(client),
test,
beforeEach,
expect,
describe,
});
});
The
sharedLockAdapterTestSuitefunction simplifies the process of testing your custom implementation ofISharedLockAdapterwithvitest.IMPORT_PATH:
"@daiso-tech/core/shared-lock/test-utilities"