This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathbootstrap.spec.js
201 lines (174 loc) · 5.59 KB
/
bootstrap.spec.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create()
const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
describe('.bootstrap', function () {
this.timeout(100 * 1000)
let ipfsd
let ipfs
before((done) => {
df.spawn((err, node) => {
expect(err).to.not.exist()
ipfsd = node
ipfs = node.api
done()
})
})
after((done) => ipfsd.stop(done))
let peers
describe('Callback API', function () {
this.timeout(100 * 1000)
describe('.add', () => {
it('returns an error when called with an invalid arg', (done) => {
ipfs.bootstrap.add(invalidArg, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
ipfs.bootstrap.add(validIp4, (err, res) => {
expect(err).to.not.exist()
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.eql(1)
done()
})
})
it('returns a list of bootstrap peers when called with the default option', (done) => {
ipfs.bootstrap.add({ default: true }, (err, res) => {
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.above(1)
done()
})
})
})
describe('.list', () => {
it('returns a list of peers', (done) => {
ipfs.bootstrap.list((err, res) => {
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist()
done()
})
})
})
describe('.rm', () => {
it('returns an error when called with an invalid arg', (done) => {
ipfs.bootstrap.rm(invalidArg, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
it('returns empty list because no peers removed when called without an arg or options', (done) => {
ipfs.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.eql(0)
done()
})
})
it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
ipfs.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.eql(0)
done()
})
})
it('returns list of all peers removed when all option is passed', (done) => {
ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
expect(err).to.not.exist()
peers = res.Peers
expect(peers).to.exist()
done()
})
})
})
})
describe('Promise API', function () {
this.timeout(100 * 1000)
describe('.add', () => {
it('returns an error when called without args or options', () => {
return ipfs.bootstrap.add(null)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('returns an error when called with an invalid arg', () => {
return ipfs.bootstrap.add(invalidArg)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('returns a list of peers when called with a valid arg (ip4)', () => {
return ipfs.bootstrap.add(validIp4)
.then((res) => {
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.eql(1)
})
})
it('returns a list of default peers when called with the default option', () => {
return ipfs.bootstrap.add(null, { default: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.above(1)
})
})
})
describe('.list', () => {
it('returns a list of peers', () => {
return ipfs.bootstrap.list()
.then((res) => {
peers = res.Peers
expect(peers).to.exist()
})
})
})
describe('.rm', () => {
it('returns an error when called with an invalid arg', () => {
return ipfs.bootstrap.rm(invalidArg)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('returns empty list when called without an arg or options', () => {
return ipfs.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.eql(0)
})
})
it('returns list containing the peer removed when called with a valid arg (ip4)', () => {
return ipfs.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist()
expect(peers.length).to.eql(0)
})
})
it('returns list of all peers removed when all option is passed', () => {
return ipfs.bootstrap.rm(null, { all: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist()
})
})
})
})
})