Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit b4ad412

Browse files
committed
feat: reworking tests with new ipfsd-ctl
1 parent e9734ee commit b4ad412

20 files changed

+101
-86
lines changed

test/cli/pubsub.js

+33-23
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ chai.use(dirtyChai)
99
const delay = require('delay')
1010
const series = require('async/series')
1111
const ipfsExec = require('../utils/ipfs-exec')
12+
const createRepo = require('../utils/create-repo-nodejs')
1213
const IPFS = require('../../src')
1314

1415
const DaemonFactory = require('ipfsd-ctl')
15-
const df = DaemonFactory.create({ type: 'js' })
16+
const df = DaemonFactory.create()
1617

1718
const config = {
1819
Bootstrap: [],
@@ -28,50 +29,59 @@ describe('pubsub', function () {
2829
this.timeout(80 * 1000)
2930

3031
let node
31-
let ipfsdA
32-
let ipfsdB
32+
let ipfsd
3333
let cli
3434
let httpApi
3535

3636
const topicA = 'nonscentsA'
3737
const topicB = 'nonscentsB'
3838
const topicC = 'nonscentsC'
3939

40+
let repo = createRepo()
4041
before(function (done) {
4142
this.timeout(60 * 1000)
4243

43-
DaemonFactory
44-
.create({ type: 'proc' })
45-
.spawn({
46-
exec: IPFS,
47-
config,
48-
args: ['--enable-pubsub-experiment']
49-
}, (err, _ipfsd) => {
50-
expect(err).to.not.exist()
51-
ipfsdA = _ipfsd
52-
node = _ipfsd.api
53-
done()
54-
})
44+
node = new IPFS({
45+
repo: createRepo(),
46+
init: { bits: 1024 },
47+
EXPERIMENTAL: {
48+
pubsub: true
49+
},
50+
config
51+
})
52+
53+
node.once('ready', () => {
54+
done()
55+
})
56+
57+
node.once('error', (err) => {
58+
done(err)
59+
})
5560
})
5661

57-
after((done) => ipfsdB.stop(done))
62+
after((done) => {
63+
node.stop((err) => {
64+
expect(err).to.not.exist()
65+
repo.teardown(done)
66+
})
67+
})
5868

5969
before((done) => {
6070
df.spawn({
71+
type: 'js',
6172
args: ['--enable-pubsub-experiment'],
62-
exec: `./src/cli/bin.js`,
73+
exec: `${process.cwd()}/src/cli/bin.js`,
6374
config
64-
}, (err, _ipfsd) => {
75+
}, (err, _node) => {
6576
expect(err).to.not.exist()
66-
httpApi = _ipfsd.api
67-
ipfsdB = _ipfsd
68-
httpApi.repoPath = ipfsdB.repoPath
77+
httpApi = _node.api
78+
ipfsd = _node
79+
httpApi.repoPath = ipfsd.repoPath
6980
done()
7081
})
7182
})
7283

73-
after((done) => ipfsdA.stop(done))
74-
after((done) => ipfsdB.stop(done))
84+
after((done) => ipfsd.stop(done))
7585

7686
before((done) => {
7787
cli = ipfsExec(httpApi.repoPath)

test/cli/swarm.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ipfsExec = require('../utils/ipfs-exec')
1212
const parallel = require('async/parallel')
1313

1414
const DaemonFactory = require('ipfsd-ctl')
15-
const df = DaemonFactory.create({ type: 'js' })
15+
const df = DaemonFactory.create()
1616

1717
const config = {
1818
Bootstrap: [],
@@ -36,15 +36,15 @@ describe('swarm', () => {
3636

3737
series([
3838
(cb) => {
39-
df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => {
39+
df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => {
4040
expect(err).to.not.exist()
4141
ipfsA = ipfsExec(node.repoPath)
4242
nodes.push(node)
4343
cb()
4444
})
4545
},
4646
(cb) => {
47-
df.spawn({ exec: `./src/cli/bin.js`, config }, (err, node) => {
47+
df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => {
4848
expect(err).to.not.exist()
4949
node.api.id((err, id) => {
5050
expect(err).to.not.exist()

test/core/bitswap.spec.js

+9-20
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const multihashing = require('multihashing-async')
1717
const CID = require('cids')
1818

1919
const DaemonFactory = require('ipfsd-ctl')
20-
const df = DaemonFactory.create({ type: 'js' })
21-
22-
const dfProc = DaemonFactory.create({ type: 'proc' })
20+
const df = DaemonFactory.create()
2321

2422
// This gets replaced by '../utils/create-repo-browser.js' in the browser
2523
const createTempRepo = require('../utils/create-repo-nodejs.js')
@@ -69,14 +67,7 @@ function connectNodes (remoteNode, inProcNode, callback) {
6967
let nodes = []
7068

7169
function addNode (inProcNode, callback) {
72-
df.spawn({
73-
exec: `./src/cli/bin.js`,
74-
config: {
75-
Addresses: {
76-
Swarm: [`/ip4/127.0.0.1/tcp/0/ws`]
77-
}
78-
}
79-
}, (err, ipfsd) => {
70+
df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, ipfsd) => {
8071
expect(err).to.not.exist()
8172
nodes.push(ipfsd)
8273
connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api))
@@ -91,7 +82,8 @@ describe('bitswap', function () {
9182
beforeEach(function (done) {
9283
this.timeout(60 * 1000)
9384

94-
let config = {
85+
let options = {
86+
repo: createTempRepo(),
9587
config: {
9688
Addresses: {
9789
Swarm: []
@@ -106,7 +98,7 @@ describe('bitswap', function () {
10698
}
10799

108100
if (isNode) {
109-
config = Object.assign(config, {
101+
options = Object.assign(options, {
110102
config: {
111103
Addresses: {
112104
Swarm: ['/ip4/127.0.0.1/tcp/0']
@@ -115,21 +107,18 @@ describe('bitswap', function () {
115107
})
116108
}
117109

118-
dfProc.spawn({ exec: IPFS, config }, (err, _ipfsd) => {
119-
expect(err).to.not.exist()
120-
nodes.push(_ipfsd)
121-
inProcNode = _ipfsd.api
122-
done()
123-
})
110+
inProcNode = new IPFS(options)
111+
inProcNode.on('ready', () => done())
124112
})
125113

126114
afterEach(function (done) {
127115
this.timeout(80 * 1000)
128116
const tasks = nodes.map((node) => (cb) => node.stop(cb))
117+
tasks.push((cb) => setTimeout(() => inProcNode.stop(() => cb()), 500))
129118
parallel(tasks, (err) => {
130119
expect(err).to.not.exist()
131120
nodes = []
132-
done()
121+
done(err)
133122
})
134123
})
135124

test/core/interface/block.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515

test/core/interface/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515
test.config(common)

test/core/interface/dag.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515

test/core/interface/dht.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
const test = require('interface-ipfs-core')
66
77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc'})
8+
const df = DaemonFactory.create()
99
1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df)
1313
}
1414
}
1515

test/core/interface/files.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515

test/core/interface/generic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515
test.generic(common)

test/core/interface/object.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515

test/core/interface/pubsub.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515

test/core/interface/swarm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const test = require('interface-ipfs-core')
55
const IPFS = require('../../../src')
66

77
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ type: 'proc' })
8+
const df = DaemonFactory.create({ remote: false })
99

1010
const common = {
1111
setup: function (callback) {
12-
callback(null, df, IPFS)
12+
callback(null, df, 'proc', IPFS)
1313
}
1414
}
1515

test/core/kad-dht.node.js

+24-8
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,42 @@ const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
99
const parallel = require('async/parallel')
10+
const IPFS = require('../../src')
1011

11-
const DaemonFactory = require('ipfsd-ctl')
12-
const df = DaemonFactory.create({ type: 'js' })
12+
const createRepo = require('../utils/create-repo-nodejs')
1313

1414
const config = {
1515
Addresses: {
16-
Swarm: [`/ip4/127.0.0.1/tcp/0`, `/ip4/127.0.0.1/tcp/0/ws`],
16+
Swarm: [`/ip4/127.0.0.1/tcp/0`],
1717
API: `/ip4/127.0.0.1/tcp/0`,
1818
Gateway: `/ip4/127.0.0.1/tcp/0`
1919
},
2020
Bootstrap: [],
2121
Discovery: {
2222
MDNS: {
23-
Enabled: false
23+
Enabled:
24+
false
2425
}
2526
}
2627
}
2728

2829
function createNode (callback) {
29-
df.spawn({ exec: './src/cli/bin.js', config }, callback)
30+
const node = new IPFS({
31+
repo: createRepo(),
32+
init: { bits: 1024 },
33+
EXPERIMENTAL: {
34+
pubsub: true
35+
},
36+
config
37+
})
38+
39+
node.once('ready', () => {
40+
callback(null, node)
41+
})
42+
43+
node.once('error', (err) => {
44+
callback(err)
45+
})
3046
}
3147

3248
describe('verify that kad-dht is doing its thing', () => {
@@ -46,9 +62,9 @@ describe('verify that kad-dht is doing its thing', () => {
4662
], (err, _nodes) => {
4763
expect(err).to.not.exist()
4864
nodes = _nodes
49-
nodeA = _nodes[0].api
50-
nodeB = _nodes[1].api
51-
nodeC = _nodes[2].api
65+
nodeA = _nodes[0]
66+
nodeB = _nodes[1]
67+
nodeC = _nodes[2]
5268
parallel([
5369
(cb) => nodeA.id(cb),
5470
(cb) => nodeB.id(cb),

test/http-api/interface/block.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
const test = require('interface-ipfs-core')
55

66
const DaemonFactory = require('ipfsd-ctl')
7-
const df = DaemonFactory.create({ type: 'js' })
7+
const df = DaemonFactory.create()
88

99
const common = {
1010
setup: function (callback) {
11-
callback(null, df, './src/cli/bin.js')
11+
callback(null, df)
1212
}
1313
}
1414

0 commit comments

Comments
 (0)