git ssb

2+

cel / ssb-party



Tree: 8b6827337d6c9a677261c5987cb95bbee685d870

Files: 8b6827337d6c9a677261c5987cb95bbee685d870 / test.js

2156 bytesRaw
1var test = require('tape')
2var pull = require('pull-stream')
3var ssbKeys = require('ssb-keys')
4var rimraf = require('rimraf')
5var path = require('path')
6var createConfig = require('ssb-config/inject')
7var fs = require('fs')
8
9var createSsbParty = require('.')
10
11var tmpDir = fs.mkdtempSync(path.join(require('os').tmpdir(), 'ssb-party-'))
12
13var sbot1, sbot2
14var opts = {
15 keys: ssbKeys.generate(),
16 skipPlugins: true,
17 party: {
18 out: 'debug.log',
19 err: true
20 },
21 path: tmpDir,
22 port: 45454,
23 timeout: 1000,
24 caps: {
25 shs: '0000000000000000000000000000000000000000000='
26 },
27 timers: {
28 keepalive: 1000
29 }
30}
31
32test('create', function (t) {
33 t.comment('dir: ' + tmpDir)
34 createSsbParty(opts, function (err, sbot, config) {
35 t.error(err, 'create ssb party')
36 sbot1 = sbot
37 t.ok(sbot, 'sbot')
38 t.ok(config, 'config')
39 t.end()
40 })
41})
42
43test('rpc', function (t) {
44 sbot1.whoami(function (err, feed) {
45 t.error(err, 'whoami')
46 t.equals(feed.id, opts.keys.id, 'id')
47 t.end()
48 })
49})
50
51test('client', function (t) {
52 createSsbParty(opts, function (err, sbot) {
53 t.error(err, 'create ssb party again')
54 t.ok(sbot, 'rpc')
55 sbot2 = sbot
56 sbot.whoami(function (err, feed) {
57 t.error(err, 'whoami')
58 t.equals(feed.id, opts.keys.id, 'id')
59 t.end()
60 })
61 })
62})
63
64test('close first rpc', function (t) {
65 sbot1.close(t.end)
66})
67
68test('second rpc still works', function (t) {
69 sbot2.whoami(function (err, feed) {
70 t.error(err, 'whoami')
71 t.equals(feed.id, opts.keys.id, 'id')
72 t.end()
73 })
74})
75
76test('stop', function (t) {
77 sbot2.control.stop(t.end)
78})
79
80test('close second rpc', function (t) {
81 sbot2.close(t.end)
82})
83
84test('autoclose', function (t) {
85 opts.timers.keepalive = 10
86 createSsbParty(opts, function (err, sbot) {
87 t.error(err, 'create')
88 sbot.close(function (err) {
89 t.error(err, 'close')
90 setTimeout(function () {
91 var log = fs.readFileSync(path.join(tmpDir, 'debug.log'), 'utf8')
92 t.ok(/sbot auto closing/.test(log), 'auto closed')
93 t.end()
94 }, 5000)
95 })
96 })
97})
98
99test('cleanup', function (t) {
100 rimraf.sync(tmpDir)
101 t.end()
102})
103

Built with git-ssb-web