Skip to content

Commit

Permalink
feat(init): Add the possibility to pass options to init()
Browse files Browse the repository at this point in the history
  • Loading branch information
haadcode authored and dignifiedquire committed Dec 20, 2016
1 parent 39beb38 commit 9c48373
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ module.exports = {
version (done) {
(new Node()).version(done)
},
local (path, done) {
local (path, opts, done) {
if (typeof opts === 'function') {
done = opts
opts = {}
}
if (!done) {
done = path
path = process.env.IPFS_PATH ||
join(process.env.HOME ||
process.env.USERPROFILE, '.ipfs')
}
process.nextTick(() => {
done(null, new Node(path))
done(null, new Node(path, opts))
})
},
disposableApi (opts, done) {
Expand Down
29 changes: 28 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ describe('ipfs executable path', function () {
})
})

describe('local daemon', function () {
const repoPath = '/tmp/ipfsd-ctl-test'
const addr = '/ip4/127.0.0.1/tcp/5678'
const config = {
Addresses: {
API: addr
}
}

it('allows passing flags to init', (done) => {
ipfsd.local(repoPath, config, (err, node) => {
assert.equal(err, null)

node.init((err) => {
assert.equal(err, null)

node.getConfig('Addresses.API', (err, res) => {
assert.equal(err, null)
assert.equal(res, addr)
rimraf(repoPath, done)
})
})
})
})
})

describe('disposable node with local api', function () {
this.timeout(20000)
let ipfs
Expand Down Expand Up @@ -345,8 +371,9 @@ describe('ipfs-api version', function () {
})
})

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

const added = res[res.length - 1]
Expand Down

0 comments on commit 9c48373

Please sign in to comment.