-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathexample.spec.ts
46 lines (35 loc) · 1.14 KB
/
example.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { createClient, RedisClient } from "redis";
import { promisify } from "util";
const globals = (global as unknown) as any;
describe("redis example suite", () => {
let redisClient: RedisClient;
beforeAll(() => {
const connectionUri = `redis://${globals.__TESTCONTAINERS_REDIS_IP__}:${globals.__TESTCONTAINERS_REDIS_PORT_6379__}`;
redisClient = createClient(connectionUri);
});
afterAll(() => {
redisClient.quit();
});
it("should set the container name correctly", () => {
expect(globals.__TESTCONTAINERS_REDIS_NAME__).toEqual(
"/unique-container-name"
);
});
it("should write correctly", async () => {
// Arrange
const setAsync = promisify(redisClient.set).bind(redisClient);
const value: number = 73;
// Act
const setResult = await setAsync("test", value.toString());
// Assert
expect(setResult).toEqual("OK");
});
it("should read the written value correctly", async () => {
// Arrange
const getAsync = promisify(redisClient.get).bind(redisClient);
// Act
const getResult = await getAsync("test");
// Assert
expect(getResult).toEqual("73");
});
});