-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
55 lines (47 loc) · 1.24 KB
/
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
var co = require('co');
var wrap = require('./');
var MemDB = require('memdb');
var Stream = require('stream');
var assert = require('assert');
var db = wrap(MemDB());
describe('co-level', function(){
it('should put and get', function(done){
co(function*(){
yield db.put('foo', 'bar');
yield db.put('bar', 'baz');
var res = yield db.get('foo');
assert.equal(res, 'bar');
})(done);
});
it('should del', function(done){
co(function*(){
yield db.put('key', 'value');
yield db.del('key');
try {
yield db.get('key');
throw new Error('did not throw');
} catch (e) {}
})(done);
});
it('should support array batch', function(done){
co(function*(){
yield db.batch([
{ type: 'put', key: 'yolo', value: 'swag' }
]);
res = yield db.get('yolo');
assert.equal(res, 'swag');
})(done);
});
it('should support chained batch', function(done){
co(function*(){
yield db.batch()
.put('swag', 'yolo')
.write();
res = yield db.get('swag');
assert.equal(res, 'yolo');
})(done);
});
it('should create streams', function(){
assert(db.createReadStream() instanceof Stream);
});
});