-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
58 lines (45 loc) · 1.21 KB
/
index.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
var tape = require('tape')
const path = require('path')
const os = require('os')
var data = [
{key: '#'+Math.random(), value: {foo: true, bar: Date.now()}},
{key: '#'+Math.random(), value: {foo: true, bar: Date.now()}},
{key: '#'+Math.random(), value: {foo: true, bar: Date.now()}}
]
module.exports = function (create, retest) {
var seed = Date.now()
var filename = path.join(os.tmpdir(), `test-flumeview-index-${seed}`)
var db = create(filename, seed)
tape('simple', function (t) {
db.append(data, function (err, m) {
if(err) throw err
t.end()
})
})
function test (t) {
db.index.get(data[0].key, function (err, value) {
if(err) throw err
t.deepEqual(value, data[0])
db.index.get(data[1].key, function (err, value) {
if(err) throw err
t.deepEqual(value, data[1])
db.index.get(data[2].key, function (err, value) {
if(err) throw err
t.deepEqual(value, data[2])
t.end()
})
})
})
}
tape('test', test)
tape('close', function (t) {
db.close(t.end)
})
tape('reload', function (t) {
db = create(filename, seed)
t.end()
})
if (retest !== false) {
tape('retest', test)
}
}