cache.test.js
1.73 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* cache 测试
*
* @author: jf<jeff.jiang@yoho.cn>
* @date: 2016/5/18
*/
'use strict';
import test from 'ava';
import cache from '../../library/cache';
let testKey = 'test_unit_key:' + (new Date()).getTime();
let testValue = 'anotherValue';
let anotherKey = 'test_unit_key2:' + (new Date()).getTime();
let anotherValue = {a: 1};
let slaveTestKey = 'test_unit_key3:' + (new Date()).getTime();
let slaveTestValue = 'anotherValue3';
test.before('set test key', (t) => {
cache.set(testKey, testValue);
cache.set(anotherKey, anotherValue);
t.pass();
});
test.after('del test key', (t) => {
cache.del(testKey);
cache.del(anotherKey);
t.pass();
});
test('cache get test', (t) => {
return cache.get(testKey).then((v) => {
t.is(v, testValue);
});
});
test('cache get multi test', (t) => {
cache.set(anotherKey, anotherValue);
return cache.getMulti([testKey, anotherKey]).then((values) => {
console.log(values);
t.is(values[testKey], testValue);
t.is(values[anotherKey], JSON.stringify(anotherValue));
});
});
test('cache get from slave test', (t) => {
return cache.getFromSlave(testKey).then((v) => {
t.is(v, testValue);
});
});
test('cache get multi from slave test', (t) => {
cache.set(anotherKey, anotherValue);
return cache.getMultiFromSlave([testKey, anotherKey]).then((values) => {
t.is(values[testKey], testValue);
t.is(values[anotherKey], JSON.stringify(anotherValue));
});
});
test('cache set to slave', (t) => {
return cache.setSlave(slaveTestKey, slaveTestValue).then(() => {
return cache.getFromSlave(slaveTestKey);
}).then((v) => {
t.is(v, slaveTestValue);
cache.del(slaveTestKey);
});
});