Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat: use new ipfsd-ctl (#186)
Browse files Browse the repository at this point in the history
* feat: use new ipfsd-ctl

* feat: allow passing daemon type and exec path to spawn

* fix: lint
  • Loading branch information
dryajov authored and daviddias committed Jan 19, 2018
1 parent 41eeba2 commit 4d4ef7f
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 83 deletions.
10 changes: 6 additions & 4 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ function expectKey (block, expected, callback) {
module.exports = (common) => {
describe('.block', () => {
let ipfs
let ipfsd

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfsd = node
ipfs = node.api
done()
})
})
})

after((done) => common.teardown(done))
after((done) => ipfsd.stop(done))

describe('.put', () => {
it('a buffer, using defaults', (done) => {
Expand Down
10 changes: 6 additions & 4 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ module.exports = (common) => {
describe('.config', function () {
this.timeout(30 * 1000)
let ipfs
let ipfsd

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfsd = node
ipfs = node.api
done()
})
})
})

after((done) => common.teardown(done))
after((done) => ipfsd.stop(done))

describe('.get', () => {
it('retrieve the whole config', (done) => {
Expand Down
10 changes: 6 additions & 4 deletions src/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ const CID = require('cids')
module.exports = (common) => {
describe('.dag', () => {
let ipfs
let ipfsd

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfs = node.api
ipfsd = node
done()
})
})
})

after((done) => common.teardown(done))
after((done) => ipfsd.stop(done))

let pbNode
let cborNode
Expand Down
37 changes: 25 additions & 12 deletions src/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ const series = require('async/series')
const parallel = require('async/parallel')
const CID = require('cids')

function spawnWithId (factory, callback) {
function spawnWithId (df, type, exec, callback) {
if (typeof type === 'function') {
callback = type
type = undefined
}

if (typeof exec === 'function') {
callback = exec
exec = undefined
}

waterfall([
(cb) => factory.spawnNode(cb),
(node, cb) => node.id((err, peerId) => {
(cb) => df.spawn({ type, exec }, cb),
(node, cb) => node.api.id((err, peerId) => {
if (err) {
return cb(err)
}
node.peerId = peerId
node.api.peerId = peerId
cb(null, node)
})
], callback)
Expand All @@ -31,23 +41,26 @@ module.exports = (common) => {
let nodeB
let nodeC

let ipfsdNodes
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type) => {
expect(err).to.not.exist()
series([
(cb) => spawnWithId(factory, cb),
(cb) => spawnWithId(factory, cb),
(cb) => spawnWithId(factory, cb)
(cb) => spawnWithId(df, type, cb),
(cb) => spawnWithId(df, type, cb),
(cb) => spawnWithId(df, type, cb)
], (err, nodes) => {
expect(err).to.not.exist()

nodeA = nodes[0]
nodeB = nodes[1]
nodeC = nodes[2]
ipfsdNodes = nodes

nodeA = nodes[0].api
nodeB = nodes[1].api
nodeC = nodes[2].api

parallel([
(cb) => nodeA.swarm.connect(nodeB.peerId.addresses[0], cb),
Expand All @@ -58,7 +71,7 @@ module.exports = (common) => {
})
})

after((done) => common.teardown(done))
after((done) => parallel(ipfsdNodes.map((node) => (cb) => node.stop(cb)), done))

describe('.get and .put', () => {
it('errors when getting a non-existent key from the DHT', (done) => {
Expand Down
10 changes: 6 additions & 4 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = (common) => {
this.timeout(40 * 1000)

let ipfs
let ipfsd

function fixture (path) {
return loadFixture(__dirname, path, 'interface-ipfs-core')
Expand Down Expand Up @@ -55,17 +56,18 @@ module.exports = (common) => {
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfs = node.api
ipfsd = node
done()
})
})
})

after((done) => common.teardown(done))
after((done) => ipfsd.stop(done))

describe('.add', () => {
it('a Buffer', (done) => {
Expand Down
12 changes: 7 additions & 5 deletions src/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ const hat = require('hat')
module.exports = (common) => {
describe('.key', () => {
const keyTypes = [
{type: 'rsa', size: 2048}
{ type: 'rsa', size: 2048 }
]
const keys = []
let ipfs
let ipfsd
let withGo

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfsd = node
ipfs = node.api
ipfs.id((err, id) => {
expect(err).to.not.exist()
withGo = id.agentVersion.startsWith('go-ipfs')
Expand All @@ -37,7 +39,7 @@ module.exports = (common) => {
})
})

after((done) => common.teardown(done))
after((done) => ipfsd.stop(done))

describe('.gen', () => {
keyTypes.forEach((kt) => {
Expand Down
12 changes: 6 additions & 6 deletions src/miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ chai.use(dirtyChai)
module.exports = (common) => {
describe('.miscellaneous', () => {
let ipfs
let ipfsd

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfs = node.api
ipfsd = node
done()
})
})
})

after((done) => {
common.teardown(done)
})
after((done) => ipfsd.stop(done))

it('.id', (done) => {
ipfs.id((err, res) => {
Expand Down
14 changes: 7 additions & 7 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ module.exports = (common) => {
this.timeout(80 * 1000)

let ipfs
let ipfsd

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfs = node.api
ipfsd = node
done()
})
})
})

after((done) => {
common.teardown(done)
})
after((done) => ipfsd.stop(done))

describe('callback API', () => {
describe('.new', () => {
Expand Down Expand Up @@ -843,7 +843,7 @@ module.exports = (common) => {
return ipfs.object.put(testObj, (err, node) => {
expect(err).to.not.exist()

return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', {enc: 'base58'})
return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', { enc: 'base58' })
.then((stats) => {
const expected = {
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
Expand Down
10 changes: 6 additions & 4 deletions src/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ module.exports = (common) => {
this.timeout(50 * 1000)

let ipfs
let ipfsd

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)

common.setup((err, factory) => {
common.setup((err, df, type, exec) => {
expect(err).to.not.exist()
factory.spawnNode((err, node) => {
df.spawn({ type, exec }, (err, node) => {
expect(err).to.not.exist()
ipfs = node
ipfs = node.api
ipfsd = node
populate()
})
})
Expand All @@ -43,7 +45,7 @@ module.exports = (common) => {
}
})

after((done) => common.teardown(done))
after((done) => ipfsd.stop(done))

describe('callback API', () => {
// 1st, because ipfs.files.add pins automatically
Expand Down

0 comments on commit 4d4ef7f

Please sign in to comment.