-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlive.js
46 lines (36 loc) · 1.02 KB
/
live.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
var pull = require('pull-stream')
var tape = require('tape')
const os = require('os')
const path = require('path')
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) {
var seed = Date.now()
var filename = path.join(os.tmpdir(), `test-flumeview-index-${seed}`)
var db = create(filename, seed)
var live = []
pull(
db.index.read({live: true, sync: false}),
pull.drain(function (data) { live.push(data) })
)
tape('simple', function (t) {
db.append(data, function (err, m) {
if(err) throw err
pull(
db.index.read({}),
pull.collect(function (err, ary){
t.deepEqual(live.sort(function (a, b) {
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0
}), ary)
t.end()
})
)
})
})
tape('close', function (t) {
db.close(t.end)
})
}