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

Commit 719f689

Browse files
committed
chore: add test to ping cli command
1 parent 5bfc313 commit 719f689

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

test/cli/ping.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* eslint max-nested-callbacks: ["error", 8] */
2+
/* eslint-env mocha */
3+
'use strict'
4+
5+
const chai = require('chai')
6+
const dirtyChai = require('dirty-chai')
7+
const expect = chai.expect
8+
chai.use(dirtyChai)
9+
const delay = require('delay')
10+
const series = require('async/series')
11+
const ipfsExec = require('../utils/ipfs-exec')
12+
13+
const DaemonFactory = require('ipfsd-ctl')
14+
const df = DaemonFactory.create({ type: 'js' })
15+
16+
const config = {
17+
Bootstrap: [],
18+
Discovery: {
19+
MDNS: {
20+
Enabled:
21+
false
22+
}
23+
}
24+
}
25+
26+
describe.only('ping', function () {
27+
this.timeout(80 * 1000)
28+
29+
let ipfsdA
30+
let ipfsdB
31+
let ipfsdBId
32+
let cli
33+
34+
before(function (done) {
35+
this.timeout(60 * 1000)
36+
37+
df.spawn({
38+
exec: './src/cli/bin.js',
39+
config,
40+
initoptions: { bits: 512 }
41+
}, (err, _ipfsd) => {
42+
expect(err).to.not.exist()
43+
ipfsdA = _ipfsd
44+
done()
45+
})
46+
})
47+
48+
before((done) => {
49+
this.timeout(60 * 1000)
50+
series([
51+
(cb) => {
52+
df.spawn({
53+
exec: `./src/cli/bin.js`,
54+
config,
55+
initOptions: { bits: 512 }
56+
}, (err, _ipfsd) => {
57+
expect(err).to.not.exist()
58+
ipfsdB = _ipfsd
59+
cb()
60+
})
61+
},
62+
(cb) => {
63+
ipfsdB.api.id((err, peerInfo) => {
64+
expect(err).to.not.exist()
65+
console.log(peerInfo)
66+
ipfsdBId = peerInfo.id
67+
cb()
68+
})
69+
}
70+
], done)
71+
})
72+
73+
after((done) => ipfsdA.stop(done))
74+
after((done) => ipfsdB.stop(done))
75+
76+
before((done) => {
77+
cli = ipfsExec(ipfsdA.repoPath)
78+
done()
79+
})
80+
81+
it('ping host', (done) => {
82+
const ping = cli(`ping ${ipfsdBId}`)
83+
const result = []
84+
ping.stdout.on('data', (packet) => {
85+
console.log('ON DATA')
86+
result.push(packet.toString())
87+
})
88+
89+
ping.stdout.on('end', (c) => {
90+
console.log('END', result)
91+
done()
92+
})
93+
94+
ping.catch((err) => {
95+
expect(err).to.not.exist()
96+
done()
97+
})
98+
})
99+
})

0 commit comments

Comments
 (0)