Use redis testcontainer

This commit is contained in:
Adria Navarro 2024-03-06 00:33:24 +01:00
parent b774987e61
commit 60f82610f6
1 changed files with 19 additions and 1 deletions

View File

@ -1,8 +1,26 @@
import { GenericContainer, StartedTestContainer } from "testcontainers"
import { generator, structures } from "../../../tests"
import RedisWrapper from "../redis"
import { env } from "../.."
describe("redis", () => {
let redis: RedisWrapper
let container: StartedTestContainer
beforeAll(async () => {
const container = await new GenericContainer("redis")
.withExposedPorts(6379)
.start()
env._set(
"REDIS_URL",
`${container.getHost()}:${container.getMappedPort(6379)}`
)
env._set("MOCK_REDIS", 0)
env._set("REDIS_PASSWORD", 0)
})
afterAll(() => container?.stop())
beforeEach(async () => {
redis = new RedisWrapper(structures.db.id())
@ -165,7 +183,7 @@ describe("redis", () => {
await redis.store(key, value)
await expect(redis.increment(key)).rejects.toThrowError(
`Redis ${key} does not contains a number`
"ERR value is not an integer or out of range"
)
})
})