From cad0288889bfcf0e89d38ef7652d7263344b33a4 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 16 May 2018 14:12:28 +0100 Subject: [PATCH] test: add interface-ipfs-core ping tests License: MIT Signed-off-by: Alan Shaw --- src/core/components/ping-pull-stream.js | 4 ++- test/core/interface/interface.spec.js | 1 + test/core/interface/ping.js | 35 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/core/interface/ping.js diff --git a/src/core/components/ping-pull-stream.js b/src/core/components/ping-pull-stream.js index 72531b8d0b..c4a2acfeae 100644 --- a/src/core/components/ping-pull-stream.js +++ b/src/core/components/ping-pull-stream.js @@ -55,7 +55,9 @@ function getPeer (libp2pNode, statusStream, peerId, cb) { try { peerId = PeerId.createFromB58String(peerId) } catch (err) { - return cb(err) + return cb(Object.assign(err, { + message: `failed to parse peer address '${peerId}': input isn't valid multihash` + })) } return libp2pNode.peerRouting.findPeer(peerId, cb) diff --git a/test/core/interface/interface.spec.js b/test/core/interface/interface.spec.js index 810b7f2198..356036adeb 100644 --- a/test/core/interface/interface.spec.js +++ b/test/core/interface/interface.spec.js @@ -16,6 +16,7 @@ describe('interface-ipfs-core tests', () => { require('./key') if (isNode) { require('./swarm') + require('./ping') require('./pubsub') require('./dht') } diff --git a/test/core/interface/ping.js b/test/core/interface/ping.js new file mode 100644 index 0000000000..cc0f85b9c1 --- /dev/null +++ b/test/core/interface/ping.js @@ -0,0 +1,35 @@ +/* eslint-env mocha */ +'use strict' + +const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + +const IPFS = require('../../../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) + +const nodes = [] +const common = { + setup: function (callback) { + callback(null, { + spawnNode: (cb) => { + df.spawn({ + initOptions: { bits: 512 } + }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) + } +} + +test.ping(common)