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

Commit 2e57c35

Browse files
committed
fix: interface and cli tests ported
plus #2625
1 parent b1a8620 commit 2e57c35

File tree

9 files changed

+98
-213
lines changed

9 files changed

+98
-213
lines changed

.aegir.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ const IPFSFactory = require('ipfsd-ctl')
44
const MockPreloadNode = require('./test/utils/mock-preload-node')
55
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')
66

7-
const promisify = require('promisify-es6')
8-
97
const ipfsdServer = IPFSFactory.createServer()
10-
const preloadNode = promisify(MockPreloadNode.createNode())
11-
const echoServer = promisify(EchoServer.createServer())
8+
const preloadNode = MockPreloadNode.createNode()
9+
const echoServer = EchoServer.createServer()
1210

1311
module.exports = {
1412
bundlesize: { maxSize: '652kB' },

test/cli/dht.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,12 @@
33
'use strict'
44

55
const { expect } = require('interface-ipfs-core/src/utils/mocha')
6-
const path = require('path')
7-
const DaemonFactory = require('ipfsd-ctl')
8-
const df = DaemonFactory.create({
9-
type: 'js',
10-
IpfsClient: require('ipfs-http-client')
11-
})
12-
6+
const factory = require('../utils/factory')
137
const ipfsExec = require('../utils/ipfs-exec')
148

15-
const daemonOpts = {
16-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
17-
config: {
18-
Bootstrap: [],
19-
Discovery: {
20-
MDNS: {
21-
Enabled: false
22-
},
23-
webRTCStar: {
24-
Enabled: false
25-
}
26-
}
27-
},
28-
initOptions: { bits: 512 }
29-
}
30-
319
// TODO: unskip when DHT is enabled: https://github.com./ipfs/js-ipfs/pull/1994
3210
describe.skip('dht', () => {
11+
const df = factory({ type: 'js' })
3312
const nodes = []
3413
let ipfsA
3514
let ipfsB
@@ -41,11 +20,11 @@ describe.skip('dht', () => {
4120
before(async function () {
4221
this.timeout(80 * 1000)
4322

44-
const ipfsdA = await df.spawn(daemonOpts)
23+
const ipfsdA = await df.spawn()
4524
ipfsA = ipfsExec(ipfsdA.repoPath)
4625
nodes.push(ipfsdA)
4726

48-
const ipfsdB = await df.spawn(daemonOpts)
27+
const ipfsdB = await df.spawn()
4928
ipfsB = ipfsExec(ipfsdB.repoPath)
5029
nodes.push(ipfsdB)
5130
})
@@ -71,7 +50,7 @@ describe.skip('dht', () => {
7150
return nodes[0].api.swarm.connect(multiaddrB)
7251
})
7352

74-
after(() => Promise.all(nodes.map((node) => node.stop())))
53+
after(() => df.clean())
7554

7655
it('should be able to put a value to the dht and get it afterwards', async function () {
7756
this.timeout(60 * 1000)

test/cli/name-pubsub.js

+10-38
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,13 @@
33
'use strict'
44

55
const { expect } = require('interface-ipfs-core/src/utils/mocha')
6+
const factory = require('../utils/factory')
67
const path = require('path')
78
const ipfsExec = require('../utils/ipfs-exec')
89

9-
const DaemonFactory = require('ipfsd-ctl')
10-
const df = DaemonFactory.create({
11-
type: 'js',
12-
IpfsClient: require('ipfs-http-client')
13-
})
14-
15-
const spawnDaemon = () => df.spawn({
16-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
17-
args: ['--enable-namesys-pubsub'],
18-
initOptions: { bits: 512 },
19-
config: {
20-
Bootstrap: [],
21-
Discovery: {
22-
MDNS: {
23-
Enabled: false
24-
},
25-
webRTCStar: {
26-
Enabled: false
27-
}
28-
}
29-
}
30-
})
31-
3210
describe('name-pubsub', () => {
3311
describe('enabled', () => {
12+
const df = factory({ type: 'js', args: ['--enable-namesys-pubsub'] })
3413
let ipfsA
3514
let ipfsB
3615
let nodeAId
@@ -44,12 +23,12 @@ describe('name-pubsub', () => {
4423
// timeout for the before step
4524
this.timeout(80 * 1000)
4625

47-
const nodeA = await spawnDaemon()
48-
ipfsA = ipfsExec(nodeA.repoPath)
26+
const nodeA = await df.spawn()
27+
ipfsA = ipfsExec(nodeA.path)
4928
nodes.push(nodeA)
5029

51-
const nodeB = await spawnDaemon()
52-
ipfsB = ipfsExec(nodeB.repoPath)
30+
const nodeB = await df.spawn()
31+
ipfsB = ipfsExec(nodeB.path)
5332
nodes.push(nodeB)
5433
})
5534

@@ -71,7 +50,7 @@ describe('name-pubsub', () => {
7150
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
7251
})
7352

74-
after(() => Promise.all(nodes.map((node) => node.stop())))
53+
after(() => df.clean())
7554

7655
describe('pubsub commands', () => {
7756
it('should get enabled state of pubsub', async function () {
@@ -114,6 +93,7 @@ describe('name-pubsub', () => {
11493
})
11594

11695
describe('disabled', () => {
96+
const df = factory({ type: 'js' })
11797
let ipfsA
11898
let node
11999

@@ -123,19 +103,11 @@ describe('name-pubsub', () => {
123103
// timeout for the before step
124104
this.timeout(80 * 1000)
125105

126-
node = await df.spawn({
127-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
128-
config: {},
129-
initOptions: { bits: 512 }
130-
})
106+
node = await df.spawn()
131107
ipfsA = ipfsExec(node.repoPath)
132108
})
133109

134-
after(() => {
135-
if (node) {
136-
return node.stop()
137-
}
138-
})
110+
after(() => df.clean())
139111

140112
it('should get disabled state of pubsub', async function () {
141113
const res = await ipfsA('name pubsub state')

test/cli/ping.js

+6-37
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,8 @@
33
'use strict'
44

55
const { expect } = require('interface-ipfs-core/src/utils/mocha')
6-
const DaemonFactory = require('ipfsd-ctl')
6+
const factory = require('../utils/factory')
77
const ipfsExec = require('../utils/ipfs-exec')
8-
const path = require('path')
9-
const df = DaemonFactory.create({
10-
type: 'js',
11-
IpfsClient: require('ipfs-http-client')
12-
})
13-
14-
const config = {
15-
Bootstrap: [],
16-
Discovery: {
17-
MDNS: {
18-
Enabled:
19-
false
20-
}
21-
}
22-
}
238

249
describe('ping', function () {
2510
this.timeout(60 * 1000)
@@ -28,15 +13,12 @@ describe('ping', function () {
2813
let bMultiaddr
2914
let ipfsdBId
3015
let cli
16+
const df = factory({ type: 'js' })
3117

3218
before(async function () {
3319
this.timeout(60 * 1000)
3420

35-
ipfsdB = await df.spawn({
36-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
37-
config,
38-
initOptions: { bits: 512 }
39-
})
21+
ipfsdB = await df.spawn()
4022
const peerInfo = await ipfsdB.api.id()
4123
ipfsdBId = peerInfo.id
4224
bMultiaddr = peerInfo.addresses[0]
@@ -45,30 +27,17 @@ describe('ping', function () {
4527
before(async function () {
4628
this.timeout(60 * 1000)
4729

48-
ipfsdA = await df.spawn({
49-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
50-
config,
51-
initOptions: { bits: 512 }
52-
})
30+
ipfsdA = await df.spawn()
5331
// Without DHT we need to have an already established connection
5432
await ipfsdA.api.swarm.connect(bMultiaddr)
5533
})
5634

5735
before(() => {
5836
this.timeout(60 * 1000)
59-
cli = ipfsExec(ipfsdA.repoPath)
37+
cli = ipfsExec(ipfsdA.path)
6038
})
6139

62-
after(() => {
63-
if (ipfsdA) {
64-
return ipfsdA.stop()
65-
}
66-
})
67-
after(() => {
68-
if (ipfsdB) {
69-
return ipfsdB.stop()
70-
}
71-
})
40+
after(() => df.clean())
7241

7342
it('ping host', async () => {
7443
this.timeout(60 * 1000)

test/cli/pubsub.js

+5-33
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha')
66
const delay = require('delay')
77
const series = require('async/series')
88
const ipfsExec = require('../utils/ipfs-exec')
9-
const IPFS = require('../../src')
10-
const path = require('path')
11-
const DaemonFactory = require('ipfsd-ctl')
12-
13-
const config = {
14-
Bootstrap: [],
15-
Discovery: {
16-
MDNS: {
17-
Enabled:
18-
false
19-
}
20-
}
21-
}
9+
const factory = require('../utils/factory')
2210

2311
describe('pubsub', function () {
2412
this.timeout(80 * 1000)
25-
13+
const df = factory()
2614
let node
2715
let ipfsdA
2816
let ipfsdB
@@ -36,15 +24,7 @@ describe('pubsub', function () {
3624
before(async function () {
3725
this.timeout(60 * 1000)
3826

39-
const df = DaemonFactory.create({
40-
type: 'proc',
41-
IpfsClient: require('ipfs-http-client')
42-
})
43-
ipfsdA = await df.spawn({
44-
exec: IPFS,
45-
initOptions: { bits: 512 },
46-
config
47-
})
27+
ipfsdA = await df.spawn({ type: 'proc' })
4828
node = ipfsdA.api
4929
})
5030

@@ -55,17 +35,9 @@ describe('pubsub', function () {
5535
})
5636

5737
before(async () => {
58-
const df = DaemonFactory.create({
59-
type: 'js',
60-
IpfsClient: require('ipfs-http-client')
61-
})
62-
ipfsdB = await df.spawn({
63-
initOptions: { bits: 512 },
64-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
65-
config
66-
})
38+
ipfsdB = await df.spawn({ type: 'js' })
6739
httpApi = ipfsdB.api
68-
httpApi.repoPath = ipfsdB.repoPath
40+
httpApi.repoPath = ipfsdB.path
6941
})
7042

7143
after(() => {

test/cli/swarm.js

+8-34
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,15 @@
44

55
const { expect } = require('interface-ipfs-core/src/utils/mocha')
66
const sinon = require('sinon')
7-
const ipfsExec = require('../utils/ipfs-exec')
8-
const path = require('path')
9-
const addrsCommand = require('../../src/cli/commands/swarm/addrs')
10-
117
const multiaddr = require('multiaddr')
128
const PeerInfo = require('peer-info')
9+
const ipfsExec = require('../utils/ipfs-exec')
1310
const PeerId = require('peer-id')
14-
15-
const DaemonFactory = require('ipfsd-ctl')
16-
const df = DaemonFactory.create({
17-
type: 'js',
18-
IpfsClient: require('ipfs-http-client')
19-
})
20-
21-
const config = {
22-
Bootstrap: [],
23-
Discovery: {
24-
MDNS: {
25-
Enabled:
26-
false
27-
}
28-
}
29-
}
11+
const addrsCommand = require('../../src/cli/commands/swarm/addrs')
12+
const factory = require('../utils/factory')
3013

3114
describe('swarm', () => {
15+
const df = factory({ type: 'js' })
3216
afterEach(() => {
3317
sinon.restore()
3418
})
@@ -39,31 +23,21 @@ describe('swarm', () => {
3923
let bMultiaddr
4024
let ipfsA
4125

42-
const nodes = []
4326
before(async function () {
4427
// CI takes longer to instantiate the daemon, so we need to increase the
4528
// timeout for the before step
4629
this.timeout(80 * 1000)
4730

4831
const res = await Promise.all([
49-
df.spawn({
50-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
51-
config,
52-
initOptions: { bits: 512 }
53-
}),
54-
df.spawn({
55-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
56-
config,
57-
initOptions: { bits: 512 }
58-
})
32+
df.spawn(),
33+
df.spawn()
5934
])
60-
ipfsA = ipfsExec(res[0].repoPath)
35+
ipfsA = ipfsExec(res[0].path)
6136
const id = await res[1].api.id()
6237
bMultiaddr = id.addresses[0]
63-
nodes.push(...res)
6438
})
6539

66-
after(() => Promise.all(nodes.map((node) => node.stop())))
40+
after(() => df.clean())
6741

6842
it('connect', async () => {
6943
const out = await ipfsA(`swarm connect ${bMultiaddr}`)

0 commit comments

Comments
 (0)