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

Commit 90b01dc

Browse files
committed
feat: use new ipfsd-ctl
1 parent b0eaa78 commit 90b01dc

32 files changed

+299
-592
lines changed

.aegir.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
'use strict'
22

3-
const factory = require('./test/ipfs-factory/tasks')
3+
const createServer = require('ipfsd-ctl').createServer
44

5+
const server = createServer()
56
module.exports = {
67
karma: {
78
files: [{
89
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
910
watched: false,
1011
served: true,
1112
included: false
12-
}]
13+
}],
14+
singleRun: true
1315
},
1416
hooks: {
15-
pre: factory.start,
16-
post: factory.stop
17+
browser: {
18+
pre: server.start.bind(server),
19+
post: server.stop.bind(server)
20+
}
1721
}
1822
}

test/bitswap.spec.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,28 @@ const chai = require('chai')
55
const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
8-
const FactoryClient = require('./ipfs-factory/client')
8+
9+
const DaemonFactory = require('ipfsd-ctl')
10+
const df = DaemonFactory.create()
911

1012
describe('.bitswap', function () {
1113
this.timeout(20 * 1000) // slow CI
12-
let ipfs
13-
let fc
14+
let ipfsd = null
1415

1516
before((done) => {
1617
this.timeout(20 * 1000) // slow CI
17-
fc = new FactoryClient()
18-
fc.spawnNode((err, node) => {
18+
df.spawn((err, node) => {
1919
expect(err).to.not.exist()
20-
ipfs = node
20+
ipfsd = node
2121
done()
2222
})
2323
})
2424

25-
after((done) => {
26-
fc.dismantle(done)
27-
})
25+
after((done) => ipfsd.stop(done))
2826

2927
describe('Callback API', () => {
3028
it('.wantlist', (done) => {
31-
ipfs.bitswap.wantlist((err, res) => {
29+
ipfsd.api.bitswap.wantlist((err, res) => {
3230
expect(err).to.not.exist()
3331
expect(res).to.have.to.be.eql({
3432
Keys: null
@@ -38,7 +36,7 @@ describe('.bitswap', function () {
3836
})
3937

4038
it('.stat', (done) => {
41-
ipfs.bitswap.stat((err, res) => {
39+
ipfsd.api.bitswap.stat((err, res) => {
4240
expect(err).to.not.exist()
4341
expect(res).to.have.property('BlocksReceived')
4442
expect(res).to.have.property('DupBlksReceived')
@@ -53,7 +51,7 @@ describe('.bitswap', function () {
5351

5452
it('.unwant', (done) => {
5553
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
56-
ipfs.bitswap.unwant(key, (err) => {
54+
ipfsd.api.bitswap.unwant(key, (err) => {
5755
expect(err).to.not.exist()
5856
done()
5957
})
@@ -62,7 +60,7 @@ describe('.bitswap', function () {
6260

6361
describe('Promise API', () => {
6462
it('.wantlist', () => {
65-
return ipfs.bitswap.wantlist()
63+
return ipfsd.api.bitswap.wantlist()
6664
.then((res) => {
6765
expect(res).to.have.to.be.eql({
6866
Keys: null
@@ -71,7 +69,7 @@ describe('.bitswap', function () {
7169
})
7270

7371
it('.stat', () => {
74-
return ipfs.bitswap.stat()
72+
return ipfsd.api.bitswap.stat()
7573
.then((res) => {
7674
expect(res).to.have.property('BlocksReceived')
7775
expect(res).to.have.property('DupBlksReceived')
@@ -84,7 +82,7 @@ describe('.bitswap', function () {
8482

8583
it('.unwant', () => {
8684
const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
87-
return ipfs.bitswap.unwant(key)
85+
return ipfsd.api.bitswap.unwant(key)
8886
})
8987
})
9088
})

test/bootstrap.spec.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,27 @@ const chai = require('chai')
66
const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
9-
const FactoryClient = require('./ipfs-factory/client')
9+
10+
const DaemonFactory = require('ipfsd-ctl')
11+
const df = DaemonFactory.create()
1012

1113
const invalidArg = 'this/Is/So/Invalid/'
1214
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
1315

1416
describe('.bootstrap', function () {
1517
this.timeout(100 * 1000)
1618

17-
let ipfs
18-
let fc
19+
let ipfsd
1920

2021
before((done) => {
21-
fc = new FactoryClient()
22-
fc.spawnNode((err, node) => {
22+
df.spawn((err, node) => {
2323
expect(err).to.not.exist()
24-
ipfs = node
24+
ipfsd = node
2525
done()
2626
})
2727
})
2828

29-
after((done) => {
30-
fc.dismantle(done)
31-
})
29+
after((done) => ipfsd.stop(done))
3230

3331
let peers
3432

@@ -37,14 +35,14 @@ describe('.bootstrap', function () {
3735

3836
describe('.add', () => {
3937
it('returns an error when called with an invalid arg', (done) => {
40-
ipfs.bootstrap.add(invalidArg, (err) => {
38+
ipfsd.api.bootstrap.add(invalidArg, (err) => {
4139
expect(err).to.be.an.instanceof(Error)
4240
done()
4341
})
4442
})
4543

4644
it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
47-
ipfs.bootstrap.add(validIp4, (err, res) => {
45+
ipfsd.api.bootstrap.add(validIp4, (err, res) => {
4846
expect(err).to.not.exist()
4947
expect(res).to.be.eql({ Peers: [validIp4] })
5048
peers = res.Peers
@@ -55,7 +53,7 @@ describe('.bootstrap', function () {
5553
})
5654

5755
it('returns a list of bootstrap peers when called with the default option', (done) => {
58-
ipfs.bootstrap.add({ default: true }, (err, res) => {
56+
ipfsd.api.bootstrap.add({ default: true }, (err, res) => {
5957
expect(err).to.not.exist()
6058
peers = res.Peers
6159
expect(peers).to.exist()
@@ -67,7 +65,7 @@ describe('.bootstrap', function () {
6765

6866
describe('.list', () => {
6967
it('returns a list of peers', (done) => {
70-
ipfs.bootstrap.list((err, res) => {
68+
ipfsd.api.bootstrap.list((err, res) => {
7169
expect(err).to.not.exist()
7270
peers = res.Peers
7371
expect(peers).to.exist()
@@ -78,14 +76,14 @@ describe('.bootstrap', function () {
7876

7977
describe('.rm', () => {
8078
it('returns an error when called with an invalid arg', (done) => {
81-
ipfs.bootstrap.rm(invalidArg, (err) => {
79+
ipfsd.api.bootstrap.rm(invalidArg, (err) => {
8280
expect(err).to.be.an.instanceof(Error)
8381
done()
8482
})
8583
})
8684

8785
it('returns empty list because no peers removed when called without an arg or options', (done) => {
88-
ipfs.bootstrap.rm(null, (err, res) => {
86+
ipfsd.api.bootstrap.rm(null, (err, res) => {
8987
expect(err).to.not.exist()
9088
peers = res.Peers
9189
expect(peers).to.exist()
@@ -95,7 +93,7 @@ describe('.bootstrap', function () {
9593
})
9694

9795
it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
98-
ipfs.bootstrap.rm(null, (err, res) => {
96+
ipfsd.api.bootstrap.rm(null, (err, res) => {
9997
expect(err).to.not.exist()
10098
peers = res.Peers
10199
expect(peers).to.exist()
@@ -105,7 +103,7 @@ describe('.bootstrap', function () {
105103
})
106104

107105
it('returns list of all peers removed when all option is passed', (done) => {
108-
ipfs.bootstrap.rm(null, { all: true }, (err, res) => {
106+
ipfsd.api.bootstrap.rm(null, { all: true }, (err, res) => {
109107
expect(err).to.not.exist()
110108
peers = res.Peers
111109
expect(peers).to.exist()
@@ -120,21 +118,21 @@ describe('.bootstrap', function () {
120118

121119
describe('.add', () => {
122120
it('returns an error when called without args or options', () => {
123-
return ipfs.bootstrap.add(null)
121+
return ipfsd.api.bootstrap.add(null)
124122
.catch((err) => {
125123
expect(err).to.be.an.instanceof(Error)
126124
})
127125
})
128126

129127
it('returns an error when called with an invalid arg', () => {
130-
return ipfs.bootstrap.add(invalidArg)
128+
return ipfsd.api.bootstrap.add(invalidArg)
131129
.catch((err) => {
132130
expect(err).to.be.an.instanceof(Error)
133131
})
134132
})
135133

136134
it('returns a list of peers when called with a valid arg (ip4)', () => {
137-
return ipfs.bootstrap.add(validIp4)
135+
return ipfsd.api.bootstrap.add(validIp4)
138136
.then((res) => {
139137
expect(res).to.be.eql({ Peers: [validIp4] })
140138
peers = res.Peers
@@ -144,7 +142,7 @@ describe('.bootstrap', function () {
144142
})
145143

146144
it('returns a list of default peers when called with the default option', () => {
147-
return ipfs.bootstrap.add(null, { default: true })
145+
return ipfsd.api.bootstrap.add(null, { default: true })
148146
.then((res) => {
149147
peers = res.Peers
150148
expect(peers).to.exist()
@@ -155,7 +153,7 @@ describe('.bootstrap', function () {
155153

156154
describe('.list', () => {
157155
it('returns a list of peers', () => {
158-
return ipfs.bootstrap.list()
156+
return ipfsd.api.bootstrap.list()
159157
.then((res) => {
160158
peers = res.Peers
161159
expect(peers).to.exist()
@@ -165,14 +163,14 @@ describe('.bootstrap', function () {
165163

166164
describe('.rm', () => {
167165
it('returns an error when called with an invalid arg', () => {
168-
return ipfs.bootstrap.rm(invalidArg)
166+
return ipfsd.api.bootstrap.rm(invalidArg)
169167
.catch((err) => {
170168
expect(err).to.be.an.instanceof(Error)
171169
})
172170
})
173171

174172
it('returns empty list when called without an arg or options', () => {
175-
return ipfs.bootstrap.rm(null)
173+
return ipfsd.api.bootstrap.rm(null)
176174
.then((res) => {
177175
peers = res.Peers
178176
expect(peers).to.exist()
@@ -181,7 +179,7 @@ describe('.bootstrap', function () {
181179
})
182180

183181
it('returns list containing the peer removed when called with a valid arg (ip4)', () => {
184-
return ipfs.bootstrap.rm(null)
182+
return ipfsd.api.bootstrap.rm(null)
185183
.then((res) => {
186184
peers = res.Peers
187185
expect(peers).to.exist()
@@ -190,7 +188,7 @@ describe('.bootstrap', function () {
190188
})
191189

192190
it('returns list of all peers removed when all option is passed', () => {
193-
return ipfs.bootstrap.rm(null, { all: true })
191+
return ipfsd.api.bootstrap.rm(null, { all: true })
194192
.then((res) => {
195193
peers = res.Peers
196194
expect(peers).to.exist()

test/commands.spec.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@ const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
88

9-
const FactoryClient = require('./ipfs-factory/client')
9+
const DaemonFactory = require('ipfsd-ctl')
10+
const df = DaemonFactory.create()
1011

1112
describe('.commands', function () {
1213
this.timeout(20 * 1000)
1314

14-
let ipfs
15-
let fc
15+
let ipfsd
1616

1717
before((done) => {
18-
fc = new FactoryClient()
19-
fc.spawnNode((err, node) => {
18+
df.spawn((err, node) => {
2019
expect(err).to.not.exist()
21-
ipfs = node
20+
ipfsd = node
2221
done()
2322
})
2423
})
2524

26-
after((done) => {
27-
fc.dismantle(done)
28-
})
25+
after((done) => ipfsd.stop(done))
2926

3027
it('lists commands', (done) => {
31-
ipfs.commands((err, res) => {
28+
ipfsd.api.commands((err, res) => {
3229
expect(err).to.not.exist()
3330
expect(res).to.exist()
3431
done()
@@ -37,7 +34,7 @@ describe('.commands', function () {
3734

3835
describe('promise', () => {
3936
it('lists commands', () => {
40-
return ipfs.commands()
37+
return ipfsd.api.commands()
4138
.then((res) => {
4239
expect(res).to.exist()
4340
})

test/constructor.spec.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const chai = require('chai')
55
const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
8-
const FactoryClient = require('./ipfs-factory/client')
8+
9+
const DaemonFactory = require('ipfsd-ctl')
10+
const df = DaemonFactory.create()
911

1012
const ipfsAPI = require('../src/index.js')
1113

@@ -22,19 +24,19 @@ function clientWorks (client, done) {
2224
describe('ipfs-api constructor tests', () => {
2325
describe('parameter permuations', () => {
2426
let apiAddr
25-
let fc
27+
let ipfsd
2628

2729
before(function (done) {
2830
this.timeout(20 * 1000) // slow CI
29-
fc = new FactoryClient()
30-
fc.spawnNode((err, node) => {
31+
df.spawn((err, node) => {
3132
expect(err).to.not.exist()
32-
apiAddr = node.apiAddr
33+
ipfsd = node
34+
apiAddr = node.apiAddr.toString()
3335
done()
3436
})
3537
})
3638

37-
after((done) => fc.dismantle(done))
39+
after((done) => ipfsd.stop(done))
3840

3941
it('opts', (done) => {
4042
const splitted = apiAddr.split('/')

0 commit comments

Comments
 (0)