Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix(bootstrap:add): prevent duplicate inserts (#893)
Browse files Browse the repository at this point in the history
* fix(bootstrap:add): prevent duplicate inserts
  • Loading branch information
kenshyx authored and daviddias committed Jul 3, 2017
1 parent 8166ca9 commit ce504cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/components/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function bootstrap (self) {
}
if (args.default) {
config.Bootstrap = defaultNodes
} else if (multiaddr) {
} else if (multiaddr && config.Bootstrap.indexOf(multiaddr) === -1) {
config.Bootstrap.push(multiaddr)
}
self._repo.config.set(config, (err) => {
Expand Down
24 changes: 24 additions & 0 deletions test/http-api/over-ipfs-api/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ module.exports = (ctl) => {
})
})

it('prevents duplicate inserts of bootstrap peers', () => {
return ctl
.bootstrap
.rm(null, { all: true })
.then((res) => {
expect(res.Peers.length).to.equal(0)
return ctl.bootstrap.add(validIp4)
})
.then(res => {
expect(res).to.be.eql({ Peers: [validIp4] })
return ctl.bootstrap.add(validIp4)
})
.then((res) => {
expect(res).to.be.eql({ Peers: [validIp4] })
return ctl.bootstrap.list()
})
.then((res) => {
expect(res).to.exist()
const insertPosition = res.Peers.indexOf(validIp4)
expect(insertPosition).to.not.equal(-1)
expect(res.Peers.length).to.equal(1)
})
})

it('returns a list of bootstrap peers when called with the default option', (done) => {
ctl.bootstrap.add({ default: true }, (err, res) => {
expect(err).to.not.exist()
Expand Down

0 comments on commit ce504cd

Please sign in to comment.