This repository has been archived by the owner on Mar 31, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
121 lines (111 loc) · 2.57 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var Lazy = require('./')
var test = require('tape')
var MemDOWN = require('memdown')
function factory (cb) {
setImmediate(function () {
var db = MemDOWN()
db.open(function (err) {
cb(err, db)
})
})
}
test('Lazy(factory)', function (t) {
t.throws(function () {
Lazy()
}, /factory required/, 'factory required')
var lazy = new Lazy(factory)
t.ok(lazy, 'creates leveldown')
t.ok(Lazy(factory), 'without new too')
t.end()
})
test('#open(opts, cb)', function (t) {
var lazy = new Lazy(factory)
t.throws(function () {
lazy.open({}, function () {})
}, /can't manually open/, 'can\'t manually open')
t.end()
})
test('#{put,get,del}()', function (t) {
t.test('integration', function (t) {
var lazy = new Lazy(factory)
lazy.put('foo', 'bar', function (err) {
t.error(err)
lazy.get('foo', function (err, val) {
t.error(err)
t.equal(val.toString(), 'bar')
lazy.del('foo', function (err) {
t.error(err)
t.end()
})
})
})
})
t.test('open guard', function (t) {
t.plan(6)
var lazy = new Lazy(factory)
lazy.put('foo', 'bar', function (err) {
t.error(err)
lazy.get('foo', function (err, val) {
t.error(err)
t.equal(val.toString(), 'bar')
})
})
lazy.put('bar', 'baz', function (err) {
t.error(err)
lazy.get('bar', function (err, val) {
t.error(err)
t.equal(val.toString(), 'baz')
})
})
})
})
test('#close(cb)', function (t) {
t.test('closed', function (t) {
var lazy = new Lazy(factory)
t.throws(function () {
lazy.close(function () {})
}, /not open/, 'not open')
t.end()
})
t.test('opening', function (t) {
t.plan(2)
var lazy = new Lazy(factory)
lazy.put('foo', 'bar', function (err) {
t.error(err)
})
lazy.close(function (err) {
t.error(err)
})
})
t.test('open', function (t) {
var lazy = new Lazy(factory)
lazy.put('foo', 'bar', function (err) {
t.error(err)
lazy.close(function (err) {
t.error(err)
t.end()
})
})
})
t.test('closing', function (t) {
t.plan(3)
var lazy = new Lazy(factory)
lazy.put('foo', 'bar', function (err) {
t.error(err)
lazy.close(function (err) {
t.error(err)
})
lazy.close(function (err) {
t.error(err)
})
})
})
})
test('#iterator(opts)', function (t) {
var lazy = new Lazy(factory)
var it = lazy.iterator({})
it.next(function () {
t.equal(arguments.length, 0, 'ended')
t.end()
})
})