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

Commit

Permalink
http-api: bootstrap + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 23, 2016
1 parent 377ee62 commit bfc3ee6
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 24 deletions.
Empty file added src/http-api/resources/block.js
Empty file.
27 changes: 27 additions & 0 deletions src/http-api/resources/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const ipfs = require('./../index.js').ipfs
const boom = require('boom')

exports = module.exports

exports.list = (request, reply) => {
ipfs.bootstrap.list((err, list) => {
if (err) {
return reply(boom.badRequest(err))
}
return reply(list)
})
}

exports.add = (request, reply) => {
// ipfs.id((err, id) => {
// if (err) { return reply(boom.badRequest(err)) }
// return reply(id)
// })
}

exports.rm = (request, reply) => {
// ipfs.id((err, id) => {
// if (err) { return reply(boom.badRequest(err)) }
// return reply(id)
// })
}
Empty file.
2 changes: 0 additions & 2 deletions src/http-api/resources/id.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const ipfs = require('./../index.js').ipfs
const boom = require('boom')

Expand Down
5 changes: 5 additions & 0 deletions src/http-api/resources/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
exports.version = require('./version')
exports.id = require('./id')
exports.bootstrap = require('./bootstrap')
exports.repo = require('./repo')
exports.object = require('./object')
exports.config = require('./config')
exports.block = require('./block')
Empty file.
Empty file added src/http-api/resources/repo.js
Empty file.
2 changes: 0 additions & 2 deletions src/http-api/resources/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const ipfs = require('./../index.js').ipfs
const boom = require('boom')

Expand Down
10 changes: 10 additions & 0 deletions src/http-api/routes/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO

api.route({
method: 'GET',
path: '/api/v0/block',
handler: resources.block
})
16 changes: 6 additions & 10 deletions src/http-api/routes/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const api = require('./../index.js').server.select('API')
const resources = require('./../resources')
const Joi = require('joi')
Expand All @@ -8,18 +6,18 @@ const Joi = require('joi')
api.route({
method: 'GET',
path: '/api/v0/bootstrap',
handler: resources.version.list
handler: resources.bootstrap.list
})

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
api.route({
method: 'GET',
path: '/api/v0/bootstrap/add',
handler: resources.version.add,
handler: resources.bootstrap.add,
config: {
validate: {
query: {
arg: Joi.string(), // multiaddr to add
arg: Joi.string().required(), // multiaddr to add
default: Joi.boolean()
}
}
Expand All @@ -30,22 +28,20 @@ api.route({
api.route({
method: 'GET',
path: '/api/v0/bootstrap/list',
handler: resources.version.list
handler: resources.bootstrap.list
})

// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
api.route({
method: 'GET',
path: '/api/v0/bootstrap/rm',
handler: resources.version.rm,
handler: resources.bootstrap.rm,
config: {
validate: {
query: {
arg: Joi.string(), // multiaddr to rm
arg: Joi.string().required(), // multiaddr to rm
all: Joi.boolean()
}
}
}

})

10 changes: 10 additions & 0 deletions src/http-api/routes/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO

api.route({
method: 'GET',
path: '/api/v0/config',
handler: resources.config
})
2 changes: 0 additions & 2 deletions src/http-api/routes/id.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

Expand Down
5 changes: 5 additions & 0 deletions src/http-api/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
require('./version')
require('./id')
require('./bootstrap')
// require('./block')
// require('./object')
// require('./repo')
// require('./config')
10 changes: 10 additions & 0 deletions src/http-api/routes/object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO

api.route({
method: 'GET',
path: '/api/v0/object',
handler: resources.object
})
10 changes: 10 additions & 0 deletions src/http-api/routes/repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

// TODO

api.route({
method: 'GET',
path: '/api/v0/repo',
handler: resources.repo
})
2 changes: 0 additions & 2 deletions src/http-api/routes/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const api = require('./../index.js').server.select('API')
const resources = require('./../resources')

Expand Down
94 changes: 88 additions & 6 deletions tests/test-http-api/test-bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,104 @@
/* eslint-env mocha */

// const expect = require('chai').expect
const expect = require('chai').expect
const APIctl = require('ipfs-api')

describe('bootstrap', () => {
describe('api', () => {
// var api
var api

it.skip('api', (done) => {
// api = require('../../src/http-api').server.select('API')
it('api', (done) => {
api = require('../../src/http-api').server.select('API')
done()
})

// TODO
it('list', (done) => {
api.inject({
method: 'GET',
url: '/api/v0/bootstrap'
}, (res) => {
expect(res.result).to.deep.equal(defaultList)
done()
})
})

it('list 2', (done) => {
api.inject({
method: 'GET',
url: '/api/v0/bootstrap/list'
}, (res) => {
expect(res.result).to.deep.equal(defaultList)
done()
})
})

it('add', (done) => {
api.inject({
method: 'GET',
url: '/api/v0/bootstrap/add',
payload: {
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
}
}, (res) => {
done()
})
})

it('rm', (done) => {
api.inject({
method: 'GET',
url: '/api/v0/bootstrap/rm',
payload: {
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
}
}, (res) => {
done()
})
})

it('confirm list is as expected', (done) => {
api.inject({
method: 'GET',
url: '/api/v0/bootstrap/list'
}, (res) => {
expect(res.result).to.deep.equal(defaultList)
done()
})
})
})

describe('gateway', () => {})

describe('using js-ipfs-api', () => {
// TODO
var ctl

it('start IPFS API ctl', (done) => {
ctl = APIctl('/ip4/127.0.0.1/tcp/6001')
done()
})

// TODO: needs https://github.com/ipfs/js-ipfs-api/issues/217
it.skip('list', (done) => {
ctl.boostrap.list((err, result) => {
expect(err).to.not.exist
expect(result).to.deep.equal(defaultList)
done()
})
})

it.skip('add', (done) => {})
it.skip('rm', (done) => {})
})
})

const defaultList = [
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
]

0 comments on commit bfc3ee6

Please sign in to comment.