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

Commit

Permalink
Merge pull request #1226 from ipfs/fix-stats-tests
Browse files Browse the repository at this point in the history
fix: stats tests
  • Loading branch information
victorb committed Feb 17, 2018
2 parents 905bdc0 + caa9556 commit 698b5b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
39 changes: 21 additions & 18 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,11 @@ describe('bitswap', function () {
expect(() => node.bitswap.wantlist()).to.throw(/online/)
})

it('.stat throws while offline', () => {
expect(() => node.bitswap.stat()).to.throw(/online/)
it('.stat gives error while offline', () => {
node.bitswap.stat((err, stats) => {
expect(err).to.exist()
expect(stats).to.not.exist()
})
})

it('throws if offline', () => {
Expand All @@ -279,22 +282,22 @@ describe('bitswap', function () {
expect(node.bitswap.wantlist()).to.eql([])
})

it('returns the stats', () => {
let stats = node.bitswap.stat()

expect(stats).to.have.keys([
'blocksReceived',
'blocksSent',
'dataReceived',
'dataSent',
'wantListLength',
'wantlist',
'peerCount',
'peers',
'providesBufferLength',
'dupDataReceived',
'dupBlksReceived'
])
it('returns the stats', (done) => {
node.bitswap.stat((err, stats) => {
expect(err).to.not.exist()
expect(stats).to.have.keys([
'blocksReceived',
'blocksSent',
'dataReceived',
'dataSent',
'wantlist',
'peers',
'provideBufLen',
'dupDataReceived',
'dupBlksReceived'
])
done()
})
})
})
})
Expand Down
17 changes: 9 additions & 8 deletions test/http-api/spec/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ module.exports = (http) => {
url: '/api/v0/bitswap/stat'
}, (res) => {
expect(res.statusCode).to.equal(200)

expect(res.result).to.have.keys([
'BlocksReceived',
'Wantlist',
'Peers',
'DupBlksReceived',
'DupDataReceived'
])
expect(res.result).to.have.property('ProvideBufLen')
expect(res.result).to.have.property('BlocksReceived')
expect(res.result).to.have.property('Wantlist')
expect(res.result).to.have.property('Peers')
expect(res.result).to.have.property('DupBlksReceived')
expect(res.result).to.have.property('DupDataReceived')
expect(res.result).to.have.property('DataReceived')
expect(res.result).to.have.property('BlocksSent')
expect(res.result).to.have.property('DataSent')
done()
})
})
Expand Down

0 comments on commit 698b5b6

Please sign in to comment.