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

Commit bfc3ee6

Browse files
committedFeb 23, 2016
http-api: bootstrap + tests
1 parent 377ee62 commit bfc3ee6

17 files changed

+171
-24
lines changed
 

‎src/http-api/resources/block.js

Whitespace-only changes.

‎src/http-api/resources/bootstrap.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const ipfs = require('./../index.js').ipfs
2+
const boom = require('boom')
3+
4+
exports = module.exports
5+
6+
exports.list = (request, reply) => {
7+
ipfs.bootstrap.list((err, list) => {
8+
if (err) {
9+
return reply(boom.badRequest(err))
10+
}
11+
return reply(list)
12+
})
13+
}
14+
15+
exports.add = (request, reply) => {
16+
// ipfs.id((err, id) => {
17+
// if (err) { return reply(boom.badRequest(err)) }
18+
// return reply(id)
19+
// })
20+
}
21+
22+
exports.rm = (request, reply) => {
23+
// ipfs.id((err, id) => {
24+
// if (err) { return reply(boom.badRequest(err)) }
25+
// return reply(id)
26+
// })
27+
}

‎src/http-api/resources/config.js

Whitespace-only changes.

‎src/http-api/resources/id.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const ipfs = require('./../index.js').ipfs
42
const boom = require('boom')
53

‎src/http-api/resources/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
exports.version = require('./version')
22
exports.id = require('./id')
3+
exports.bootstrap = require('./bootstrap')
4+
exports.repo = require('./repo')
5+
exports.object = require('./object')
6+
exports.config = require('./config')
7+
exports.block = require('./block')

‎src/http-api/resources/object.js

Whitespace-only changes.

‎src/http-api/resources/repo.js

Whitespace-only changes.

‎src/http-api/resources/version.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const ipfs = require('./../index.js').ipfs
42
const boom = require('boom')
53

‎src/http-api/routes/block.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const api = require('./../index.js').server.select('API')
2+
const resources = require('./../resources')
3+
4+
// TODO
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/block',
9+
handler: resources.block
10+
})

‎src/http-api/routes/bootstrap.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const api = require('./../index.js').server.select('API')
42
const resources = require('./../resources')
53
const Joi = require('joi')
@@ -8,18 +6,18 @@ const Joi = require('joi')
86
api.route({
97
method: 'GET',
108
path: '/api/v0/bootstrap',
11-
handler: resources.version.list
9+
handler: resources.bootstrap.list
1210
})
1311

1412
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866
1513
api.route({
1614
method: 'GET',
1715
path: '/api/v0/bootstrap/add',
18-
handler: resources.version.add,
16+
handler: resources.bootstrap.add,
1917
config: {
2018
validate: {
2119
query: {
22-
arg: Joi.string(), // multiaddr to add
20+
arg: Joi.string().required(), // multiaddr to add
2321
default: Joi.boolean()
2422
}
2523
}
@@ -30,22 +28,20 @@ api.route({
3028
api.route({
3129
method: 'GET',
3230
path: '/api/v0/bootstrap/list',
33-
handler: resources.version.list
31+
handler: resources.bootstrap.list
3432
})
3533

3634
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L1131
3735
api.route({
3836
method: 'GET',
3937
path: '/api/v0/bootstrap/rm',
40-
handler: resources.version.rm,
38+
handler: resources.bootstrap.rm,
4139
config: {
4240
validate: {
4341
query: {
44-
arg: Joi.string(), // multiaddr to rm
42+
arg: Joi.string().required(), // multiaddr to rm
4543
all: Joi.boolean()
4644
}
4745
}
4846
}
49-
5047
})
51-

‎src/http-api/routes/config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const api = require('./../index.js').server.select('API')
2+
const resources = require('./../resources')
3+
4+
// TODO
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/config',
9+
handler: resources.config
10+
})

‎src/http-api/routes/id.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const api = require('./../index.js').server.select('API')
42
const resources = require('./../resources')
53

‎src/http-api/routes/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
require('./version')
22
require('./id')
3+
require('./bootstrap')
4+
// require('./block')
5+
// require('./object')
6+
// require('./repo')
7+
// require('./config')

‎src/http-api/routes/object.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const api = require('./../index.js').server.select('API')
2+
const resources = require('./../resources')
3+
4+
// TODO
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/object',
9+
handler: resources.object
10+
})

‎src/http-api/routes/repo.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const api = require('./../index.js').server.select('API')
2+
const resources = require('./../resources')
3+
4+
// TODO
5+
6+
api.route({
7+
method: 'GET',
8+
path: '/api/v0/repo',
9+
handler: resources.repo
10+
})

‎src/http-api/routes/version.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const api = require('./../index.js').server.select('API')
42
const resources = require('./../resources')
53

‎tests/test-http-api/test-bootstrap.js

+88-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,104 @@
11
/* eslint-env mocha */
22

3-
// const expect = require('chai').expect
3+
const expect = require('chai').expect
4+
const APIctl = require('ipfs-api')
45

56
describe('bootstrap', () => {
67
describe('api', () => {
7-
// var api
8+
var api
89

9-
it.skip('api', (done) => {
10-
// api = require('../../src/http-api').server.select('API')
10+
it('api', (done) => {
11+
api = require('../../src/http-api').server.select('API')
1112
done()
1213
})
1314

14-
// TODO
15+
it('list', (done) => {
16+
api.inject({
17+
method: 'GET',
18+
url: '/api/v0/bootstrap'
19+
}, (res) => {
20+
expect(res.result).to.deep.equal(defaultList)
21+
done()
22+
})
23+
})
24+
25+
it('list 2', (done) => {
26+
api.inject({
27+
method: 'GET',
28+
url: '/api/v0/bootstrap/list'
29+
}, (res) => {
30+
expect(res.result).to.deep.equal(defaultList)
31+
done()
32+
})
33+
})
34+
35+
it('add', (done) => {
36+
api.inject({
37+
method: 'GET',
38+
url: '/api/v0/bootstrap/add',
39+
payload: {
40+
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
41+
}
42+
}, (res) => {
43+
done()
44+
})
45+
})
46+
47+
it('rm', (done) => {
48+
api.inject({
49+
method: 'GET',
50+
url: '/api/v0/bootstrap/rm',
51+
payload: {
52+
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
53+
}
54+
}, (res) => {
55+
done()
56+
})
57+
})
58+
59+
it('confirm list is as expected', (done) => {
60+
api.inject({
61+
method: 'GET',
62+
url: '/api/v0/bootstrap/list'
63+
}, (res) => {
64+
expect(res.result).to.deep.equal(defaultList)
65+
done()
66+
})
67+
})
1568
})
1669

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

1972
describe('using js-ipfs-api', () => {
20-
// TODO
73+
var ctl
74+
75+
it('start IPFS API ctl', (done) => {
76+
ctl = APIctl('/ip4/127.0.0.1/tcp/6001')
77+
done()
78+
})
79+
80+
// TODO: needs https://github.com/ipfs/js-ipfs-api/issues/217
81+
it.skip('list', (done) => {
82+
ctl.boostrap.list((err, result) => {
83+
expect(err).to.not.exist
84+
expect(result).to.deep.equal(defaultList)
85+
done()
86+
})
87+
})
88+
89+
it.skip('add', (done) => {})
90+
it.skip('rm', (done) => {})
2191
})
2292
})
93+
94+
const defaultList = [
95+
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
96+
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
97+
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
98+
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
99+
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
100+
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
101+
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
102+
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
103+
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
104+
]

0 commit comments

Comments
 (0)
This repository has been archived.