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

Commit 3c951bf

Browse files
committed
feat: rework interface tests
1 parent fca2314 commit 3c951bf

File tree

15 files changed

+302
-31
lines changed

15 files changed

+302
-31
lines changed

test/core/interface/block.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn((err, _ipfsd) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
nodes.push(_ipfsd)
23+
cb(null, _ipfsd.api)
24+
})
25+
}
26+
})
27+
},
28+
teardown: function (callback) {
29+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1330
}
1431
}
1532

test/core/interface/config.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn((err, _ipfsd) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
nodes.push(_ipfsd)
23+
cb(null, _ipfsd.api)
24+
})
25+
}
26+
})
27+
},
28+
teardown: function (callback) {
29+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1330
}
1431
}
32+
1533
test.config(common)

test/core/interface/dag.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn((err, _ipfsd) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
nodes.push(_ipfsd)
23+
cb(null, _ipfsd.api)
24+
})
25+
}
26+
})
27+
},
28+
teardown: function (callback) {
29+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1330
}
1431
}
1532

test/core/interface/dht.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,30 @@
33

44
/*
55
const test = require('interface-ipfs-core')
6+
const parallel = require('async/parallel')
67
78
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create()
9+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
910
11+
const nodes = []
1012
const common = {
1113
setup: function (callback) {
12-
callback(null, df)
14+
callback(null, {
15+
spawnNode: (cb) => {
16+
df.spawn((err, _ipfsd) => {
17+
if (err) {
18+
return cb(err)
19+
}
20+
21+
nodes.push(_ipfsd)
22+
cb(null, _ipfsd.api)
23+
})
24+
}
25+
})
26+
},
27+
teardown: function (callback) {
28+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1329
}
1430
}
15-
1631
test.dht(common)
1732
*/

test/core/interface/files.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn((err, _ipfsd) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
nodes.push(_ipfsd)
23+
cb(null, _ipfsd.api)
24+
})
25+
}
26+
})
27+
},
28+
teardown: function (callback) {
29+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1330
}
1431
}
1532

test/core/interface/generic.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn((err, _ipfsd) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
nodes.push(_ipfsd)
23+
cb(null, _ipfsd.api)
24+
})
25+
}
26+
})
27+
},
28+
teardown: function (callback) {
29+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1330
}
1431
}
32+
1533
test.generic(common)

test/core/interface/object.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn((err, _ipfsd) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
nodes.push(_ipfsd)
23+
cb(null, _ipfsd.api)
24+
})
25+
}
26+
})
27+
},
28+
teardown: function (callback) {
29+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1330
}
1431
}
1532

test/core/interface/pubsub.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (cb) => {
17+
df.spawn({ args: ['--enable-pubsub-experiment'] },
18+
(err, _ipfsd) => {
19+
if (err) {
20+
return cb(err)
21+
}
22+
23+
nodes.push(_ipfsd)
24+
cb(null, _ipfsd.api)
25+
})
26+
}
27+
})
28+
},
29+
teardown: function (callback) {
30+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1331
}
1432
}
1533

test/core/interface/swarm.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,41 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
6+
57
const IPFS = require('../../../src')
68

79
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({ remote: false })
10+
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })
911

12+
const nodes = []
1013
const common = {
1114
setup: function (callback) {
12-
callback(null, df, 'proc', IPFS)
15+
callback(null, {
16+
spawnNode: (repoPath, config, cb) => {
17+
if (typeof repoPath === 'function') {
18+
cb = repoPath
19+
repoPath = undefined
20+
}
21+
22+
if (typeof config === 'function') {
23+
cb = config
24+
config = undefined
25+
}
26+
27+
df.spawn({ repoPath, config }, (err, _ipfsd) => {
28+
if (err) {
29+
return cb(err)
30+
}
31+
32+
nodes.push(_ipfsd)
33+
cb(null, _ipfsd.api)
34+
})
35+
}
36+
})
37+
},
38+
teardown: function (callback) {
39+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1340
}
1441
}
1542

test/http-api/interface/block.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
56

67
const DaemonFactory = require('ipfsd-ctl')
7-
const df = DaemonFactory.create()
8+
const df = DaemonFactory.create({ exec: 'src/cli/bin.js' })
89

10+
const nodes = []
911
const common = {
1012
setup: function (callback) {
11-
callback(null, df)
13+
callback(null, {
14+
spawnNode: (cb) => {
15+
df.spawn((err, _ipfsd) => {
16+
if (err) {
17+
return cb(err)
18+
}
19+
20+
nodes.push(_ipfsd)
21+
cb(null, _ipfsd.api)
22+
})
23+
}
24+
})
25+
},
26+
teardown: function (callback) {
27+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1228
}
1329
}
1430

test/http-api/interface/config.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@
22
'use strict'
33

44
const test = require('interface-ipfs-core')
5+
const parallel = require('async/parallel')
56

67
const DaemonFactory = require('ipfsd-ctl')
7-
const df = DaemonFactory.create()
8+
const df = DaemonFactory.create({ exec: 'src/cli/bin.js' })
89

10+
const nodes = []
911
const common = {
1012
setup: function (callback) {
11-
callback(null, df, 'js', './src/cli/bin.js')
13+
callback(null, {
14+
spawnNode: (cb) => {
15+
df.spawn((err, _ipfsd) => {
16+
if (err) {
17+
return cb(err)
18+
}
19+
20+
nodes.push(_ipfsd)
21+
cb(null, _ipfsd.api)
22+
})
23+
}
24+
})
25+
},
26+
teardown: function (callback) {
27+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
1228
}
1329
}
1430

0 commit comments

Comments
 (0)