-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbatch-prefix-test.js
79 lines (74 loc) · 2.59 KB
/
batch-prefix-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
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
71
72
73
74
75
76
77
78
'use strict';
var db1, db2, db3;
var RedisDown = require('../');
module.exports.setUp = function (redisdown, test, testCommon) {
test('setUp common', testCommon.setUp);
};
module.exports.args = function (redisdown, test, testCommon) {
test('batch prefix across redisdown instances', function (t) {
db1 = redisdown(testCommon.location());
db1.__getPrefix = function (prefix) {
if (!prefix) { return this.location; }
if (typeof prefix === 'string') { return prefix; } // string prefix
if (prefix instanceof RedisDown) { return prefix.location; } // RedisDown instance
if (prefix && prefix.toString() === 'LevelUP') { // LevelUP instance
// levelup v2
if (prefix._db instanceof RedisDown) { return prefix._db.location; }
// levelup v1
if (prefix.options && prefix.options.db) { return prefix.location; }
}
// not applicable to these tests
t.fail();
};
db2 = redisdown(testCommon.location());
db3 = redisdown(testCommon.location());
db1.open({}, function (e) {
t.notOk(e, 'no error');
db2.open({}, function (e) {
t.notOk(e, 'no error');
db3.open({}, function (e) {
t.notOk(e, 'no error');
db1.batch([
{type: 'put', key: 'foo1', value: 'bar1'},
{type: 'put', key: 'foo2', value: 'bar2', prefix: db2},
{type: 'put', key: 'foo3', value: 'bar3', prefix: db3.location},
], function (e) {
t.notOk(e, 'no error');
db1.get('foo1', {asBuffer: false}, function (e, val) {
t.notOk(e, 'no error');
t.equal(val, 'bar1');
db2.get('foo2', {asBuffer: false}, function (e, val) {
t.notOk(e, 'no error');
t.equal(val, 'bar2');
db3.get('foo3', {asBuffer: false}, function (e, val) {
t.notOk(e, 'no error');
t.equal(val, 'bar3');
t.end();
})
})
})
});
});
});
});
})
};
module.exports.tearDown = function (test, testCommon) {
test('tearDown', function (t) {
db1.close(function (e) {
t.notOk(e, 'no error');
db2.close(function (e) {
t.notOk(e, 'no error');
db3.close(function (e) {
t.notOk(e, 'no error');
testCommon.tearDown(t);
});
});
});
});
};
module.exports.all = function (redisdown, test, testCommon) {
module.exports.setUp(redisdown, test, testCommon);
module.exports.args(redisdown, test, testCommon);
module.exports.tearDown(test, testCommon);
};