Skip to content

Commit cdeb6fc

Browse files
committed
Testing
2 parents f6ba307 + 8984b77 commit cdeb6fc

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
tmp
22
node_modules
33
data.jawn
4+
hyperkv-examples.js

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
"parse-input-stream": "^1.0.1",
2929
"path": "~0.12.7",
3030
"tape": "~4.5.1",
31-
"through2": "^2.0.1"
31+
"through2": "^2.0.1",
32+
"hyperkv": "^1.5.2",
33+
"hyperlog": "^4.8.1",
34+
"subleveldown": "^2.1.0"
3235
},
3336
"devDependencies": {
3437
"standard": "^6.0.5",

test/hyperkv.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 memdb = require('memdb')
9+
10+
test('import rows to hyperkv', function (t) {
11+
var db = memdb()
12+
var kv = hyperkv({
13+
log: hyperlog(sub(db, 'log'), {valueEncoding: 'json'}),
14+
db: sub(db, 'kv')
15+
})
16+
17+
var hs = kv.createHistoryStream()
18+
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+
hs.on('data', verifyBlock)
27+
hs.on('end', countBlocks)
28+
29+
function verifyBlock (block) {
30+
t.same(block.toString(), expected.shift(), 'blocks matched imported line')
31+
}
32+
33+
function countBlocks (err) {
34+
if (err) { console.log(err) }
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+
data.pipe(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+
}

0 commit comments

Comments
 (0)