Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 53b1fd9

Browse files
richardschneiderdaviddias
authored andcommitted
test: add the bootstrap tests
1 parent 427338e commit 53b1fd9

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed

js/src/bootstrap.js

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 8] */
3+
'use strict'
4+
5+
const chai = require('chai')
6+
const dirtyChai = require('dirty-chai')
7+
const expect = chai.expect
8+
chai.use(dirtyChai)
9+
10+
const invalidArg = 'this/Is/So/Invalid/'
11+
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
12+
13+
module.exports = (common) => {
14+
describe('.bootstrap', function () {
15+
16+
let ipfs
17+
let peers
18+
19+
before(function (done) {
20+
// CI takes longer to instantiate the daemon, so we need to increase the
21+
// timeout for the before step
22+
this.timeout(60 * 1000)
23+
24+
common.setup((err, factory) => {
25+
expect(err).to.not.exist()
26+
factory.spawnNode((err, node) => {
27+
expect(err).to.not.exist()
28+
ipfs = node
29+
done()
30+
})
31+
})
32+
})
33+
34+
after((done) => common.teardown(done))
35+
36+
describe('Callback API', function () {
37+
this.timeout(100 * 1000)
38+
39+
describe('.add', () => {
40+
it('returns an error when called with an invalid arg', (done) => {
41+
ipfs.bootstrap.add(invalidArg, (err) => {
42+
expect(err).to.be.an.instanceof(Error)
43+
done()
44+
})
45+
})
46+
47+
it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
48+
ipfs.bootstrap.add(validIp4, (err, res) => {
49+
expect(err).to.not.exist()
50+
expect(res).to.be.eql({ Peers: [validIp4] })
51+
peers = res.Peers
52+
expect(peers).to.exist()
53+
expect(peers.length).to.eql(1)
54+
done()
55+
})
56+
})
57+
58+
it('returns a list of bootstrap peers when called with the default option', (done) => {
59+
ipfs.bootstrap.add({ default: true }, (err, res) => {
60+
expect(err).to.not.exist()
61+
peers = res.Peers
62+
expect(peers).to.exist()
63+
expect(peers.length).to.above(1)
64+
done()
65+
})
66+
})
67+
})
68+
69+
describe('.list', () => {
70+
it('returns a list of peers', (done) => {
71+
ipfs.bootstrap.list((err, res) => {
72+
expect(err).to.not.exist()
73+
peers = res.Peers
74+
expect(peers).to.exist()
75+
done()
76+
})
77+
})
78+
})
79+
80+
describe('.rm', () => {
81+
it('returns an error when called with an invalid arg', (done) => {
82+
ipfs.bootstrap.rm(invalidArg, (err) => {
83+
expect(err).to.be.an.instanceof(Error)
84+
done()
85+
})
86+
})
87+
88+
it('returns empty list because no peers removed when called without an arg or options', (done) => {
89+
ipfs.bootstrap.rm(null, (err, res) => {
90+
expect(err).to.not.exist()
91+
peers = res.Peers
92+
expect(peers).to.exist()
93+
expect(peers.length).to.eql(0)
94+
done()
95+
})
96+
})
97+
98+
it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
99+
ipfs.bootstrap.rm(null, (err, res) => {
100+
expect(err).to.not.exist()
101+
peers = res.Peers
102+
expect(peers).to.exist()
103+
expect(peers.length).to.eql(0)
104+
done()
105+
})
106+
})
107+
108+
it('returns list of all peers removed when all option is passed', (done) => {
109+
ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
110+
expect(err).to.not.exist()
111+
peers = res.Peers
112+
expect(peers).to.exist()
113+
done()
114+
})
115+
})
116+
})
117+
})
118+
119+
describe('Promise API', function () {
120+
this.timeout(100 * 1000)
121+
122+
describe('.add', () => {
123+
it('returns an error when called without args or options', () => {
124+
return ipfs.bootstrap.add(null)
125+
.catch((err) => {
126+
expect(err).to.be.an.instanceof(Error)
127+
})
128+
})
129+
130+
it('returns an error when called with an invalid arg', () => {
131+
return ipfs.bootstrap.add(invalidArg)
132+
.catch((err) => {
133+
expect(err).to.be.an.instanceof(Error)
134+
})
135+
})
136+
137+
it('returns a list of peers when called with a valid arg (ip4)', () => {
138+
return ipfs.bootstrap.add(validIp4)
139+
.then((res) => {
140+
expect(res).to.be.eql({ Peers: [validIp4] })
141+
peers = res.Peers
142+
expect(peers).to.exist()
143+
expect(peers.length).to.eql(1)
144+
})
145+
})
146+
147+
it('returns a list of default peers when called with the default option', () => {
148+
return ipfs.bootstrap.add(null, { default: true })
149+
.then((res) => {
150+
peers = res.Peers
151+
expect(peers).to.exist()
152+
expect(peers.length).to.above(1)
153+
})
154+
})
155+
})
156+
157+
describe('.list', () => {
158+
it('returns a list of peers', () => {
159+
return ipfs.bootstrap.list()
160+
.then((res) => {
161+
peers = res.Peers
162+
expect(peers).to.exist()
163+
})
164+
})
165+
})
166+
167+
describe('.rm', () => {
168+
it('returns an error when called with an invalid arg', () => {
169+
return ipfs.bootstrap.rm(invalidArg)
170+
.catch((err) => {
171+
expect(err).to.be.an.instanceof(Error)
172+
})
173+
})
174+
175+
it('returns empty list when called without an arg or options', () => {
176+
return ipfs.bootstrap.rm(null)
177+
.then((res) => {
178+
peers = res.Peers
179+
expect(peers).to.exist()
180+
expect(peers.length).to.eql(0)
181+
})
182+
})
183+
184+
it('returns list containing the peer removed when called with a valid arg (ip4)', () => {
185+
return ipfs.bootstrap.rm(null)
186+
.then((res) => {
187+
peers = res.Peers
188+
expect(peers).to.exist()
189+
expect(peers.length).to.eql(0)
190+
})
191+
})
192+
193+
it('returns list of all peers removed when all option is passed', () => {
194+
return ipfs.bootstrap.rm(null, { all: true })
195+
.then((res) => {
196+
peers = res.Peers
197+
expect(peers).to.exist()
198+
})
199+
})
200+
})
201+
})
202+
})
203+
}

js/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ exports.pubsub = require('./pubsub')
1515
exports.key = require('./key')
1616
exports.stats = require('./stats')
1717
exports.repo = require('./repo')
18+
exports.bootstrap = require('./bootstrap')

0 commit comments

Comments
 (0)