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

Commit 7a5c571

Browse files
more happy tests
1 parent b9200f1 commit 7a5c571

File tree

6 files changed

+43
-48
lines changed

6 files changed

+43
-48
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"ncp": "^2.0.0",
6767
"nexpect": "^0.5.0",
6868
"pre-commit": "^1.2.1",
69+
"qs": "^6.3.0",
6970
"rimraf": "^2.5.4",
7071
"stream-to-promise": "^2.2.0",
7172
"transform-loader": "^0.2.3"

src/core/components/bootstrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function bootstrap (self) {
2323
}
2424
if (args.default) {
2525
config.Bootstrap = defaultNodes
26-
} else {
26+
} else if (multiaddr) {
2727
config.Bootstrap.push(multiaddr)
2828
}
2929
self._repo.config.set(config, (err) => {

src/http-api/resources/bootstrap.js

-15
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ function applyError (reply, err) {
1111
}).code(500).takeover()
1212
}
1313

14-
// common pre request handler that parses the args and returns `key` which is assigned to `request.pre.args`
15-
exports.parseKey = (request, reply) => {
16-
if (!request.query.arg) {
17-
return applyError(reply, new Error("Argument 'multiaddr' is required"))
18-
}
19-
20-
try {
21-
return reply({
22-
addr: multiaddr(request.query.arg)
23-
})
24-
} catch (err) {
25-
return applyError(reply, new Error('Not a valid multiaddr'))
26-
}
27-
}
28-
2914
exports.list = (request, reply) => {
3015
const ipfs = request.server.app.ipfs
3116

src/http-api/routes/bootstrap.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ module.exports = (server) => {
99
api.route({
1010
method: '*',
1111
path: '/api/v0/bootstrap',
12-
handler: resources.bootstrap.list
12+
config: {
13+
handler: resources.bootstrap.list
14+
}
1315
})
1416

1517
// https://github.com/ipfs/http-api-spec/blob/master/apiary.apib#L866

test/http-api/custom-ipfs-api/test-bootstrap.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const expect = require('chai').expect
66
module.exports = (ctl) => {
77
describe('.bootstrap', () => {
88
const invalidArg = 'this/Is/So/Invalid/'
9-
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
9+
const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
1010
let peers
1111

1212
describe('.add', () => {
@@ -30,7 +30,6 @@ module.exports = (ctl) => {
3030
expect(err).to.not.exist
3131
peers = res.Peers
3232
expect(peers).to.exist
33-
console.log(peers)
3433
expect(peers.length).to.be.above(1)
3534
done()
3635
})

test/http-api/inject/test-bootstrap.js

+37-29
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@
22
'use strict'
33

44
const expect = require('chai').expect
5+
const qs = require('qs')
6+
const defaultList = require('../../../src/init-files/default-config.json').Bootstrap
57

68
module.exports = (http) => {
79
describe('/bootstrap', () => {
10+
const validIp4 = '/ip4/101.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
811
let api
912

10-
before(() => {
13+
before((done) => {
1114
api = http.api.server.select('API')
15+
api.inject({
16+
method: 'GET',
17+
url: '/api/v0/bootstrap/add',
18+
payload: {
19+
default: 'true'
20+
}
21+
}, () => done())
1222
})
1323

1424
it('/list', (done) => {
1525
api.inject({
1626
method: 'GET',
1727
url: '/api/v0/bootstrap/list'
1828
}, (res) => {
19-
expect(res.result).to.deep.equal(defaultList)
29+
expect(res.statusCode).to.be.eql(200)
30+
expect(res.result.Peers).to.deep.equal(defaultList)
2031
done()
2132
})
2233
})
@@ -26,54 +37,51 @@ module.exports = (http) => {
2637
method: 'GET',
2738
url: '/api/v0/bootstrap'
2839
}, (res) => {
29-
expect(res.result).to.deep.equal(defaultList)
40+
expect(res.statusCode).to.be.eql(200)
41+
expect(res.result.Peers).to.deep.equal(defaultList)
3042
done()
3143
})
3244
})
3345

34-
it.skip('/add', (done) => { // TODO
46+
it('/add', (done) => {
47+
const query = {
48+
arg: validIp4
49+
}
50+
3551
api.inject({
3652
method: 'GET',
37-
url: '/api/v0/bootstrap/add',
38-
payload: {
39-
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
40-
}
53+
url: `/api/v0/bootstrap/add?${qs.stringify(query)}`
4154
}, (res) => {
42-
// TODO assess
55+
expect(res.statusCode).to.be.eql(200)
56+
expect(res.result.Peers).to.be.eql([validIp4])
57+
done()
4358
})
4459
})
4560

46-
it.skip('/rm', (done) => { // TODO
61+
it('/rm', (done) => {
62+
const query = {
63+
arg: validIp4
64+
}
65+
4766
api.inject({
4867
method: 'GET',
49-
url: '/api/v0/bootstrap/rm',
50-
payload: {
51-
arg: '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
52-
}
68+
url: `/api/v0/bootstrap/rm?${qs.stringify(query)}`
5369
}, (res) => {
54-
// TODO assess
70+
expect(res.statusCode).to.be.eql(200)
71+
expect(res.result.Peers).to.be.eql([validIp4])
72+
done()
5573
})
5674
})
5775

58-
it.skip('/list confirm it changed', (done) => { // TODO
76+
it('/list confirm it changed', (done) => {
5977
api.inject({
6078
method: 'GET',
6179
url: '/api/v0/bootstrap/list'
6280
}, (res) => {
63-
// TODO assess
81+
expect(res.statusCode).to.be.eql(200)
82+
expect(res.result.Peers).to.be.eql(defaultList)
83+
done()
6484
})
6585
})
6686
})
6787
}
68-
69-
const defaultList = [
70-
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
71-
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
72-
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
73-
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
74-
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
75-
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
76-
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
77-
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
78-
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
79-
]

0 commit comments

Comments
 (0)