-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
41 lines (28 loc) · 906 Bytes
/
test.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
/* eslint-disable import/no-extraneous-dependencies */
const tap = require('tap');
const redis = require('./index');
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
tap.test('createClient', async (t) => {
const client = redis.createClient();
t.type(client, 'AsyncRedis');
t.end();
});
tap.test('set', async (t) => {
const client = redis.createClient();
t.equal(await client.set('test', 'val'), 'OK');
t.end();
});
tap.test('get', async (t) => {
const client = redis.createClient();
await client.set('test', 'val');
t.equal(await client.get('test'), 'val');
t.end();
});
tap.test('set/get with timeout', async (t) => {
const client = redis.createClient();
t.equal(await client.set('timeout', 'val', 'EX', 1), 'OK');
t.equal(await client.get('timeout'), 'val');
await sleep(2000);
t.equal(await client.get('timeout'), null);
t.end();
});