Skip to content

Commit 9c48373

Browse files
haadcodedignifiedquire
authored andcommittedDec 20, 2016
feat(init): Add the possibility to pass options to init()
1 parent 39beb38 commit 9c48373

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
 

‎src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ module.exports = {
1313
version (done) {
1414
(new Node()).version(done)
1515
},
16-
local (path, done) {
16+
local (path, opts, done) {
17+
if (typeof opts === 'function') {
18+
done = opts
19+
opts = {}
20+
}
1721
if (!done) {
1822
done = path
1923
path = process.env.IPFS_PATH ||
2024
join(process.env.HOME ||
2125
process.env.USERPROFILE, '.ipfs')
2226
}
2327
process.nextTick(() => {
24-
done(null, new Node(path))
28+
done(null, new Node(path, opts))
2529
})
2630
},
2731
disposableApi (opts, done) {

‎test/index.spec.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ describe('ipfs executable path', function () {
5353
})
5454
})
5555

56+
describe('local daemon', function () {
57+
const repoPath = '/tmp/ipfsd-ctl-test'
58+
const addr = '/ip4/127.0.0.1/tcp/5678'
59+
const config = {
60+
Addresses: {
61+
API: addr
62+
}
63+
}
64+
65+
it('allows passing flags to init', (done) => {
66+
ipfsd.local(repoPath, config, (err, node) => {
67+
assert.equal(err, null)
68+
69+
node.init((err) => {
70+
assert.equal(err, null)
71+
72+
node.getConfig('Addresses.API', (err, res) => {
73+
assert.equal(err, null)
74+
assert.equal(res, addr)
75+
rimraf(repoPath, done)
76+
})
77+
})
78+
})
79+
})
80+
})
81+
5682
describe('disposable node with local api', function () {
5783
this.timeout(20000)
5884
let ipfs
@@ -345,8 +371,9 @@ describe('ipfs-api version', function () {
345371
})
346372
})
347373

374+
// NOTE: if you change ./fixtures, the hash will need to be changed
348375
it('uses the correct ipfs-api', (done) => {
349-
ipfs.util.addFromFs(path.join(__dirname, 'fixtures'), { recursive: true }, (err, res) => {
376+
ipfs.util.addFromFs(path.join(__dirname, 'fixtures/'), { recursive: true }, (err, res) => {
350377
if (err) throw err
351378

352379
const added = res[res.length - 1]

0 commit comments

Comments
 (0)