-
Notifications
You must be signed in to change notification settings - Fork 75
/
close.js
41 lines (32 loc) · 889 Bytes
/
close.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
'use strict'
var tape = require('tape')
var pull = require('pull-stream')
var keys = require('ssb-keys').generate()
var createSSB = require('./util/create-ssb')
var content = { type: 'whatever' }
const name = `test-ssb-close-${Date.now()}`
tape('close (loads and closes)', function (t) {
t.plan(2)
var ssb = createSSB(name, { keys, temp: false })
ssb.publish(content, function (err, msg) {
if (err) throw err
ssb.close(function (err) {
t.error(err)
t.ok(true, 'closes + runs callback')
})
})
})
tape('close (reopen existing db)', function (t) {
t.plan(2)
var ssb = createSSB(name, { keys, temp: false })
pull(
ssb.createLogStream(),
pull.collect(function (err, ary) {
if (err) throw err
t.deepEqual(ary[0].value.content, content, 'reopen works fine')
ssb.close((err) => {
t.error(err)
})
})
)
})