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

Commit 4d4ef7f

Browse files
dryajovdaviddias
authored andcommitted
feat: use new ipfsd-ctl (#186)
* feat: use new ipfsd-ctl * feat: allow passing daemon type and exec path to spawn * fix: lint
1 parent 41eeba2 commit 4d4ef7f

File tree

11 files changed

+137
-83
lines changed

11 files changed

+137
-83
lines changed

src/block.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,25 @@ function expectKey (block, expected, callback) {
2020
module.exports = (common) => {
2121
describe('.block', () => {
2222
let ipfs
23+
let ipfsd
2324

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

29-
common.setup((err, factory) => {
30+
common.setup((err, df, type, exec) => {
3031
expect(err).to.not.exist()
31-
factory.spawnNode((err, node) => {
32+
df.spawn({ type, exec }, (err, node) => {
3233
expect(err).to.not.exist()
33-
ipfs = node
34+
ipfsd = node
35+
ipfs = node.api
3436
done()
3537
})
3638
})
3739
})
3840

39-
after((done) => common.teardown(done))
41+
after((done) => ipfsd.stop(done))
4042

4143
describe('.put', () => {
4244
it('a buffer, using defaults', (done) => {

src/config.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ module.exports = (common) => {
1212
describe('.config', function () {
1313
this.timeout(30 * 1000)
1414
let ipfs
15+
let ipfsd
1516

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

21-
common.setup((err, factory) => {
22+
common.setup((err, df, type, exec) => {
2223
expect(err).to.not.exist()
23-
factory.spawnNode((err, node) => {
24+
df.spawn({ type, exec }, (err, node) => {
2425
expect(err).to.not.exist()
25-
ipfs = node
26+
ipfsd = node
27+
ipfs = node.api
2628
done()
2729
})
2830
})
2931
})
3032

31-
after((done) => common.teardown(done))
33+
after((done) => ipfsd.stop(done))
3234

3335
describe('.get', () => {
3436
it('retrieve the whole config', (done) => {

src/dag.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@ const CID = require('cids')
1717
module.exports = (common) => {
1818
describe('.dag', () => {
1919
let ipfs
20+
let ipfsd
2021

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

26-
common.setup((err, factory) => {
27+
common.setup((err, df, type, exec) => {
2728
expect(err).to.not.exist()
28-
factory.spawnNode((err, node) => {
29+
df.spawn({ type, exec }, (err, node) => {
2930
expect(err).to.not.exist()
30-
ipfs = node
31+
ipfs = node.api
32+
ipfsd = node
3133
done()
3234
})
3335
})
3436
})
3537

36-
after((done) => common.teardown(done))
38+
after((done) => ipfsd.stop(done))
3739

3840
let pbNode
3941
let cborNode

src/dht.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@ const series = require('async/series')
1010
const parallel = require('async/parallel')
1111
const CID = require('cids')
1212

13-
function spawnWithId (factory, callback) {
13+
function spawnWithId (df, type, exec, callback) {
14+
if (typeof type === 'function') {
15+
callback = type
16+
type = undefined
17+
}
18+
19+
if (typeof exec === 'function') {
20+
callback = exec
21+
exec = undefined
22+
}
23+
1424
waterfall([
15-
(cb) => factory.spawnNode(cb),
16-
(node, cb) => node.id((err, peerId) => {
25+
(cb) => df.spawn({ type, exec }, cb),
26+
(node, cb) => node.api.id((err, peerId) => {
1727
if (err) {
1828
return cb(err)
1929
}
20-
node.peerId = peerId
30+
node.api.peerId = peerId
2131
cb(null, node)
2232
})
2333
], callback)
@@ -31,23 +41,26 @@ module.exports = (common) => {
3141
let nodeB
3242
let nodeC
3343

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

39-
common.setup((err, factory) => {
50+
common.setup((err, df, type) => {
4051
expect(err).to.not.exist()
4152
series([
42-
(cb) => spawnWithId(factory, cb),
43-
(cb) => spawnWithId(factory, cb),
44-
(cb) => spawnWithId(factory, cb)
53+
(cb) => spawnWithId(df, type, cb),
54+
(cb) => spawnWithId(df, type, cb),
55+
(cb) => spawnWithId(df, type, cb)
4556
], (err, nodes) => {
4657
expect(err).to.not.exist()
4758

48-
nodeA = nodes[0]
49-
nodeB = nodes[1]
50-
nodeC = nodes[2]
59+
ipfsdNodes = nodes
60+
61+
nodeA = nodes[0].api
62+
nodeB = nodes[1].api
63+
nodeC = nodes[2].api
5164

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

61-
after((done) => common.teardown(done))
74+
after((done) => parallel(ipfsdNodes.map((node) => (cb) => node.stop(cb)), done))
6275

6376
describe('.get and .put', () => {
6477
it('errors when getting a non-existent key from the DHT', (done) => {

src/files.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = (common) => {
2424
this.timeout(40 * 1000)
2525

2626
let ipfs
27+
let ipfsd
2728

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

58-
common.setup((err, factory) => {
59+
common.setup((err, df, type, exec) => {
5960
expect(err).to.not.exist()
60-
factory.spawnNode((err, node) => {
61+
df.spawn({ type, exec }, (err, node) => {
6162
expect(err).to.not.exist()
62-
ipfs = node
63+
ipfs = node.api
64+
ipfsd = node
6365
done()
6466
})
6567
})
6668
})
6769

68-
after((done) => common.teardown(done))
70+
after((done) => ipfsd.stop(done))
6971

7072
describe('.add', () => {
7173
it('a Buffer', (done) => {

src/key.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ const hat = require('hat')
1212
module.exports = (common) => {
1313
describe('.key', () => {
1414
const keyTypes = [
15-
{type: 'rsa', size: 2048}
15+
{ type: 'rsa', size: 2048 }
1616
]
1717
const keys = []
1818
let ipfs
19+
let ipfsd
1920
let withGo
2021

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

26-
common.setup((err, factory) => {
27+
common.setup((err, df, type, exec) => {
2728
expect(err).to.not.exist()
28-
factory.spawnNode((err, node) => {
29+
df.spawn({ type, exec }, (err, node) => {
2930
expect(err).to.not.exist()
30-
ipfs = node
31+
ipfsd = node
32+
ipfs = node.api
3133
ipfs.id((err, id) => {
3234
expect(err).to.not.exist()
3335
withGo = id.agentVersion.startsWith('go-ipfs')
@@ -37,7 +39,7 @@ module.exports = (common) => {
3739
})
3840
})
3941

40-
after((done) => common.teardown(done))
42+
after((done) => ipfsd.stop(done))
4143

4244
describe('.gen', () => {
4345
keyTypes.forEach((kt) => {

src/miscellaneous.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ chai.use(dirtyChai)
1111
module.exports = (common) => {
1212
describe('.miscellaneous', () => {
1313
let ipfs
14+
let ipfsd
1415

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

20-
common.setup((err, factory) => {
21+
common.setup((err, df, type, exec) => {
2122
expect(err).to.not.exist()
22-
factory.spawnNode((err, node) => {
23+
df.spawn({ type, exec }, (err, node) => {
2324
expect(err).to.not.exist()
24-
ipfs = node
25+
ipfs = node.api
26+
ipfsd = node
2527
done()
2628
})
2729
})
2830
})
2931

30-
after((done) => {
31-
common.teardown(done)
32-
})
32+
after((done) => ipfsd.stop(done))
3333

3434
it('.id', (done) => {
3535
ipfs.id((err, res) => {

src/object.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ module.exports = (common) => {
1717
this.timeout(80 * 1000)
1818

1919
let ipfs
20+
let ipfsd
2021

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

26-
common.setup((err, factory) => {
27+
common.setup((err, df, type, exec) => {
2728
expect(err).to.not.exist()
28-
factory.spawnNode((err, node) => {
29+
df.spawn({ type, exec }, (err, node) => {
2930
expect(err).to.not.exist()
30-
ipfs = node
31+
ipfs = node.api
32+
ipfsd = node
3133
done()
3234
})
3335
})
3436
})
3537

36-
after((done) => {
37-
common.teardown(done)
38-
})
38+
after((done) => ipfsd.stop(done))
3939

4040
describe('callback API', () => {
4141
describe('.new', () => {
@@ -843,7 +843,7 @@ module.exports = (common) => {
843843
return ipfs.object.put(testObj, (err, node) => {
844844
expect(err).to.not.exist()
845845

846-
return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', {enc: 'base58'})
846+
return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', { enc: 'base58' })
847847
.then((stats) => {
848848
const expected = {
849849
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',

src/pin.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ module.exports = (common) => {
1717
this.timeout(50 * 1000)
1818

1919
let ipfs
20+
let ipfsd
2021

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

26-
common.setup((err, factory) => {
27+
common.setup((err, df, type, exec) => {
2728
expect(err).to.not.exist()
28-
factory.spawnNode((err, node) => {
29+
df.spawn({ type, exec }, (err, node) => {
2930
expect(err).to.not.exist()
30-
ipfs = node
31+
ipfs = node.api
32+
ipfsd = node
3133
populate()
3234
})
3335
})
@@ -43,7 +45,7 @@ module.exports = (common) => {
4345
}
4446
})
4547

46-
after((done) => common.teardown(done))
48+
after((done) => ipfsd.stop(done))
4749

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

0 commit comments

Comments
 (0)