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

Commit 18e9c55

Browse files
committed
fix: interface and cli tests ported
plus #2625
1 parent 60f841f commit 18e9c55

File tree

12 files changed

+107
-221
lines changed

12 files changed

+107
-221
lines changed

.aegir.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
'use strict'
22

33
const IPFSFactory = require('ipfsd-ctl')
4-
const parallel = require('async/parallel')
54
const MockPreloadNode = require('./test/utils/mock-preload-node')
65
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')
7-
const callbackify = require('callbackify')
8-
9-
const promisify = require('promisify-es6')
106

117
const ipfsdServer = IPFSFactory.createServer()
12-
const preloadNode = promisify(MockPreloadNode.createNode())
13-
const echoServer = promisify(EchoServer.createServer())
8+
const preloadNode = MockPreloadNode.createNode()
9+
const echoServer = EchoServer.createServer()
1410

1511
module.exports = {
1612
bundlesize: { maxSize: '650kB' },

src/core/components/bootstrap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ module.exports = function bootstrap (self) {
4545
throw invalidMultiaddrError(multiaddr)
4646
}
4747

48+
let res = []
4849
const config = await self._repo.config.get()
4950
if (args.all) {
51+
res = config.Bootstrap
5052
config.Bootstrap = []
5153
} else {
5254
config.Bootstrap = config.Bootstrap.filter((mh) => mh !== multiaddr)
5355
}
5456

5557
await self._repo.config.set(config)
5658

57-
const res = []
5859
if (!args.all && multiaddr) {
5960
res.push(multiaddr)
6061
}

test/cli/bootstrap.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ describe('bootstrap', () => runOnAndOff((thing) => {
9494
it('rm all bootstrap nodes', async function () {
9595
this.timeout(40 * 1000)
9696

97-
const out = await ipfs('bootstrap rm --all')
98-
expect(out).to.equal('')
97+
const outListBefore = await ipfs('bootstrap list')
9998

100-
const out2 = await ipfs('bootstrap list')
101-
expect(out2).to.equal('')
99+
const outRm = await ipfs('bootstrap rm --all')
100+
expect(outRm).to.equal(outListBefore)
101+
102+
const outListAfter = await ipfs('bootstrap list')
103+
expect(outListAfter).to.equal('')
102104
})
103105
}))

test/cli/dht.js

Lines changed: 5 additions & 26 deletions
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

Lines changed: 10 additions & 38 deletions
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

Lines changed: 6 additions & 37 deletions
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

Lines changed: 5 additions & 33 deletions
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(() => {

0 commit comments

Comments
 (0)