Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: remove antipattern from ping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 31, 2018
1 parent f571feb commit 2e822b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions js/src/ping/ping-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ module.exports = (createCommon, options) => {
expect(res.success).to.be.false()
}
}, (err) => {
expect(err).to.exist()
expect(err).to.not.exist()
done()
})
)
})

it('should fail when pinging an invalid peer over pull stream', (done) => {
it('should fail when pinging an invalid peer id over pull stream', (done) => {
const invalidPeerId = 'not a peer ID'
const count = 2
pull(
ipfsA.pingPullStream(invalidPeerId, { count }),
pull.collect((err) => {
pull.collect((err, results) => {
expect(err).to.exist()
expect(err.message).to.include('failed to parse peer address')
expect(results).to.not.exist()
done()
})
)
Expand Down
6 changes: 3 additions & 3 deletions js/src/ping/ping-readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = (createCommon, options) => {
)
})

it('should fail when pinging an unknown peer over readable stream', (done) => {
it('should fail when pinging peer that is not available over readable stream', (done) => {
let messageNum = 0
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
const count = 2
Expand All @@ -95,13 +95,13 @@ module.exports = (createCommon, options) => {
}
}),
(err) => {
expect(err).to.exist()
expect(err).to.not.exist()
done()
}
)
})

it('should fail when pinging an invalid peer over readable stream', (done) => {
it('should fail when pinging an invalid peer id over readable stream', (done) => {
const invalidPeerId = 'not a peer ID'
const count = 2

Expand Down
11 changes: 6 additions & 5 deletions js/src/ping/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,25 @@ module.exports = (createCommon, options) => {
})
})

it('should fail when pinging an unknown peer', (done) => {
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
it('should fail when pinging a peer that is not available', (done) => {
const notAvailablePeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
const count = 2

ipfsA.ping(unknownPeerId, { count }, (err, responses) => {
expect(err).to.exist()
ipfsA.ping(notAvailablePeerId, { count }, (err, responses) => {
expect(err).to.not.exist()
expect(responses[0].text).to.include('Looking up')
expect(responses[1].success).to.be.false()
done()
})
})

it('should fail when pinging an invalid peer', (done) => {
it('should fail when pinging an invalid peer Id', (done) => {
const invalidPeerId = 'not a peer ID'
const count = 2
ipfsA.ping(invalidPeerId, { count }, (err, responses) => {
expect(err).to.exist()
expect(err.message).to.include('failed to parse peer address')
expect(responses).to.not.exist()
done()
})
})
Expand Down

0 comments on commit 2e822b6

Please sign in to comment.