Skip to content

Commit eda7381

Browse files
committed
Test for putting data to hyperkv
1 parent 06e863f commit eda7381

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/hyperkv.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var test = require('tape')
2+
var fs = require('fs')
3+
var path = require('path')
4+
var hyperkv = require('hyperkv')
5+
var hyperlog = require('hyperlog')
6+
var sub = require('subleveldown')
7+
var through = require('through2')
8+
var miss = require('mississippi')
9+
var memdb = require('memdb')
10+
11+
test('import rows to hyperkv', function (t) {
12+
var db = memdb()
13+
var kv = hyperkv({
14+
log: hyperlog(sub(db, 'log'), {valueEncoding: 'json'}),
15+
db: sub(db, 'kv')
16+
})
17+
18+
var importStream = importFromFile(kv, 'dummy.json')
19+
20+
var expected = [
21+
'{"foo":"bar","name":"josie","age":"35"}',
22+
'{"foo":"baz","name":"eloise","age":"71"}',
23+
'{"foo":"baz","name":"francoise","age":"5"}'
24+
]
25+
26+
importStream.on('finish', verify)
27+
28+
function verify (err) {
29+
if (err) { console.log(err) }
30+
var hs = kv.createHistoryStream('test')
31+
hs.on('data', function (block) {
32+
t.same(block.toString(), expected.shift(), 'blocks matched imported line')
33+
})
34+
35+
t.end()
36+
}
37+
})
38+
39+
function fixture (name) {
40+
return path.join(__dirname, 'data', name)
41+
}
42+
43+
function importFromFile (kv, file) {
44+
var data = fs.createReadStream(fixture(file))
45+
var tr = through(putData, end)
46+
47+
var importStream = miss.pipeline(data, tr)
48+
49+
function putData (row, _, next) {
50+
kv.put('test', row.toString())
51+
next()
52+
}
53+
54+
function end (done) {
55+
done()
56+
}
57+
58+
return importStream
59+
}

0 commit comments

Comments
 (0)