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

Commit fc75166

Browse files
committed
chore: dedup tests
1 parent df01cc5 commit fc75166

File tree

1 file changed

+56
-143
lines changed

1 file changed

+56
-143
lines changed

js/src/bootstrap.js

+56-143
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrS
1212

1313
module.exports = (common) => {
1414
describe('.bootstrap', function () {
15+
this.timeout(100 * 1000)
1516

1617
let ipfs
1718
let peers
@@ -33,169 +34,81 @@ module.exports = (common) => {
3334

3435
after((done) => common.teardown(done))
3536

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(null, { 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-
})
37+
describe('.add', () => {
38+
it('returns an error when called with an invalid arg', (done) => {
39+
ipfs.bootstrap.add(invalidArg, (err) => {
40+
expect(err).to.be.an.instanceof(Error)
41+
done()
6642
})
6743
})
6844

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-
})
45+
it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
46+
ipfs.bootstrap.add(validIp4, (err, res) => {
47+
expect(err).to.not.exist()
48+
expect(res).to.be.eql({ Peers: [validIp4] })
49+
peers = res.Peers
50+
expect(peers).to.exist()
51+
expect(peers.length).to.eql(1)
52+
done()
7753
})
7854
})
7955

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-
})
56+
it('returns a list of bootstrap peers when called with the default option', (done) => {
57+
ipfs.bootstrap.add(null, { default: true }, (err, res) => {
58+
expect(err).to.not.exist()
59+
peers = res.Peers
60+
expect(peers).to.exist()
61+
expect(peers.length).to.above(1)
62+
done()
11563
})
11664
})
11765
})
11866

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-
})
67+
describe('.list', () => {
68+
it('returns a list of peers', (done) => {
69+
ipfs.bootstrap.list((err, res) => {
70+
expect(err).to.not.exist()
71+
peers = res.Peers
72+
expect(peers).to.exist()
73+
done()
15474
})
15575
})
76+
})
15677

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-
})
78+
describe('.rm', () => {
79+
it('returns an error when called with an invalid arg', (done) => {
80+
ipfs.bootstrap.rm(invalidArg, (err) => {
81+
expect(err).to.be.an.instanceof(Error)
82+
done()
16483
})
16584
})
16685

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-
})
86+
it('returns empty list because no peers removed when called without an arg or options', (done) => {
87+
ipfs.bootstrap.rm(null, (err, res) => {
88+
expect(err).to.not.exist()
89+
peers = res.Peers
90+
expect(peers).to.exist()
91+
expect(peers.length).to.eql(0)
92+
done()
18293
})
94+
})
18395

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-
})
96+
it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
97+
ipfs.bootstrap.rm(null, (err, res) => {
98+
expect(err).to.not.exist()
99+
peers = res.Peers
100+
expect(peers).to.exist()
101+
expect(peers.length).to.eql(0)
102+
done()
191103
})
104+
})
192105

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-
})
106+
it('returns list of all peers removed when all option is passed', (done) => {
107+
ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
108+
expect(err).to.not.exist()
109+
peers = res.Peers
110+
expect(peers).to.exist()
111+
done()
199112
})
200113
})
201114
})

0 commit comments

Comments
 (0)