-
Notifications
You must be signed in to change notification settings - Fork 16
/
example.spec.js
41 lines (31 loc) · 1018 Bytes
/
example.spec.js
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
const redis = require('redis');
const { promisify } = require('util');
describe('docker compose example suite', () => {
let redisClient;
beforeAll(() => {
const connectionUri = `redis://${global.__TESTCONTAINERS_REDIS_IP__}:${global.__TESTCONTAINERS_REDIS_PORT_6379__}`;
redisClient = redis.createClient(connectionUri);
});
afterAll(() => {
redisClient.quit();
});
it("should set a container name", () => {
expect(global.__TESTCONTAINERS_REDIS_NAME__).toBeDefined();
});
it('should write correctly', async () => {
// Arrange
const setAsync = promisify(redisClient.set).bind(redisClient);
// Act
const setResult = await setAsync('test', 73);
// 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');
});
});