/
open2.js
79 lines (60 loc) · 1.86 KB
/
open2.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
//test to open scuttlebutt from leveldb.
var rimraf = require('rimraf')
var levelup = require('levelup')
var SubLevel = require('level-sublevel')
var Model = require('scuttlebutt/model')
var LevelScuttlebutt
= require('..')
var Client = require('../client')
var mac = require('macgyver')().autoValidate()
var tape = require('tape')
function create (c) {
return function () {
return new c
}
}
tape('local open, remote open', function (t) {
var path = '/tmp/test-scuttlebutt-remote'
t.plan(1)
rimraf(path, function () {
var db = SubLevel(levelup(path))
var schema = {foo: create(Model), bar: create(Model)}
LevelScuttlebutt(db, 'test', schema)
var local = db.scuttlebutt
var remote = Client(schema, 'test-client')
var a, b
remote.open('foo1', mac(function (err, _a) {
if(err) t.fail(err)
a = _a
console.log('OPEN foo1')
a.on('change', mac(function (k, r) {
console.log(this.name, k, r)
}).times(3))
a.set('x', Math.random())
a.set('y', Math.random())
a.set('z', Math.random())
console.log('A', a.history())
if(a && b) t.notDeepEqual(a.history(), b.history()), t.end()
}).once())
remote.open('bar1', mac(function (err, _b) {
b = _b
console.log('OPEN bar1')
b.on('change', mac(function (k, r) {
console.log(this.name, k, r)
}).times(3))
b.set('a', Math.random())
b.set('b', Math.random())
b.set('c', Math.random())
console.log('B', b.history())
if(a && b) t.notDeepEqual(a.history(), b.history()), t.end()
}).once())
console.log('>>>>>>>>>>>>>>>>')
var ls = local.createRemoteStream()
console.log('<<<<<<<<<<<<<<<<')
var rs = remote.createStream()
console.log(rs)
rs.on('data', console.log)
// ls.on('data', console.log)
ls.pipe(rs).pipe(ls)
})
})