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 296
Enhancement: Implement Bootstrap API #298
Merged
daviddias
merged 1 commit into
ipfs-inactive:master
from
gavinmcdermott:feat/implement_bootstrap
Jun 22, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
const command = require('../cmd-helpers').command | ||
|
||
module.exports = (send) => { | ||
return { | ||
add: (arg, opts, cb) => { | ||
if (typeof opts === 'function' && cb === undefined) { | ||
cb = opts | ||
opts = {} | ||
} | ||
return send('bootstrap/add', arg, opts, null, cb) | ||
}, | ||
rm: (arg, opts, cb) => { | ||
if (typeof opts === 'function' && cb === undefined) { | ||
cb = opts | ||
opts = {} | ||
} | ||
return send('bootstrap/rm', arg, opts, null, cb) | ||
}, | ||
list: command(send, 'bootstrap/list') | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* eslint-env mocha */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
|
||
const invalidArg = 'this/Is/So/Invalid/' | ||
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' | ||
|
||
describe('.bootstrap', () => { | ||
let peers | ||
|
||
describe('.add', () => { | ||
it('returns an error when called without args or options', (done) => { | ||
return apiClients.a.bootstrap.add(null, (err) => { | ||
expect(err).to.be.an.instanceof(Error) | ||
done() | ||
}) | ||
}) | ||
|
||
it('returns an error when called with an invalid arg', (done) => { | ||
return apiClients.a.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) => { | ||
return apiClients.a.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) => { | ||
return apiClients.a.bootstrap.add(null, { 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) => { | ||
return apiClients.a.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) => { | ||
return apiClients.a.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) => { | ||
return apiClients.a.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) => { | ||
return apiClients.a.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) => { | ||
return apiClients.a.bootstrap.rm(null, { all: true }, (err, res) => { | ||
expect(err).to.not.exist | ||
peers = res.Peers | ||
expect(peers).to.exist | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.promise', () => { | ||
describe('.add', () => { | ||
it('returns an error when called without args or options', () => { | ||
return apiClients.a.bootstrap.add(null) | ||
.catch((err) => { | ||
expect(err).to.be.an.instanceof(Error) | ||
}) | ||
}) | ||
|
||
it('returns an error when called with an invalid arg', () => { | ||
return apiClients.a.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 apiClients.a.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 apiClients.a.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 apiClients.a.bootstrap.list() | ||
.then((res) => { | ||
peers = res.Peers | ||
expect(peers).to.exist | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.rm', () => { | ||
it('returns an error when called with an invalid arg', () => { | ||
return apiClients.a.bootstrap.rm(invalidArg) | ||
.catch((err) => { | ||
expect(err).to.be.an.instanceof(Error) | ||
}) | ||
}) | ||
|
||
it('returns empty list when called without an arg or options', () => { | ||
return apiClients.a.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 apiClients.a.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 apiClients.a.bootstrap.rm(null, { all: true }) | ||
.then((res) => { | ||
peers = res.Peers | ||
expect(peers).to.exist | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean 'delete all'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. According to the spec there is an explicit 'delete all' call—you just have to pass an
all: true
option in order to remove all bootstrap peers. The returned array contains the list of peers that were removed in the call (I'll also make theit
string a better description).