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

Commit f834e73

Browse files
author
Pedro Santos
committed
test: add human readable test to stats bitswap
1 parent 7cf6782 commit f834e73

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

src/bitswap/stat.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const waterfall = require('async/waterfall')
55
const { getDescribe, getIt, expect } = require('../utils/mocha')
6-
const { expectIsBitswap } = require('../stats/utils')
6+
const { expectIsBitswap, expectIsBitswapHumanReadable } = require('../stats/utils')
77

88
module.exports = (createCommon, options) => {
99
const describe = getDescribe(options)
@@ -46,30 +46,7 @@ module.exports = (createCommon, options) => {
4646
it('should get human readable bitswap stats', async () => {
4747
const stats = await ipfs.bitswap.stat({ human: true })
4848

49-
expect(stats).to.exist()
50-
expect(stats).to.have.a.property('provideBufLen')
51-
.and.to.be.a('number')
52-
expect(stats).to.have.a.property('blocksReceived')
53-
.and.to.be.a('number')
54-
expect(stats).to.have.a.property('wantlist')
55-
.and.to.be.a('string')
56-
.and.to.match(/\[\d+\skeys\]$/gm)
57-
expect(stats).to.have.a.property('peers')
58-
.and.to.be.a('string')
59-
.and.to.match(/\[\d+\]$/gm)
60-
expect(stats).to.have.a.property('dupBlksReceived')
61-
.and.to.be.a('number')
62-
expect(stats).to.have.a.property('dupDataReceived')
63-
.and.to.be.a('string')
64-
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
65-
expect(stats).to.have.a.property('dataReceived')
66-
.and.to.be.a('string')
67-
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
68-
expect(stats).to.have.a.property('blocksSent')
69-
.and.to.be.a('number')
70-
expect(stats).to.have.a.property('dataSent')
71-
.and.to.be.a('string')
72-
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
49+
expectIsBitswapHumanReadable(null, stats)
7350
})
7451

7552
it('should not get bitswap stats when offline', function (done) {

src/stats/bitswap.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict'
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
5-
const { expectIsBitswap } = require('./utils')
5+
const { expectIsBitswap, expectIsBitswapHumanReadable } = require('./utils')
66

77
module.exports = (createCommon, options) => {
88
const describe = getDescribe(options)
@@ -41,5 +41,11 @@ module.exports = (createCommon, options) => {
4141
expectIsBitswap(null, res)
4242
})
4343
})
44+
45+
it('should get human readable bitswap stats', async () => {
46+
const stats = await ipfs.stats.bitswap({ human: true })
47+
48+
expectIsBitswapHumanReadable(null, stats)
49+
})
4450
})
4551
}

src/stats/utils.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,34 @@ exports.expectIsBitswap = (err, stats) => {
3030
expect(isBigInt(stats.dupDataReceived)).to.eql(true)
3131
}
3232

33+
exports.expectIsBitswapHumanReadable = (err, stats) => {
34+
expect(err).to.not.exist()
35+
expect(stats).to.exist()
36+
expect(stats).to.have.a.property('provideBufLen')
37+
.and.to.be.a('number')
38+
expect(stats).to.have.a.property('blocksReceived')
39+
.and.to.be.a('number')
40+
expect(stats).to.have.a.property('wantlist')
41+
.and.to.be.a('string')
42+
.and.to.match(/\[\d+\skeys\]$/gm)
43+
expect(stats).to.have.a.property('peers')
44+
.and.to.be.a('string')
45+
.and.to.match(/\[\d+\]$/gm)
46+
expect(stats).to.have.a.property('dupBlksReceived')
47+
.and.to.be.a('number')
48+
expect(stats).to.have.a.property('dupDataReceived')
49+
.and.to.be.a('string')
50+
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
51+
expect(stats).to.have.a.property('dataReceived')
52+
.and.to.be.a('string')
53+
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
54+
expect(stats).to.have.a.property('blocksSent')
55+
.and.to.be.a('number')
56+
expect(stats).to.have.a.property('dataSent')
57+
.and.to.be.a('string')
58+
.and.to.match(/[\d.]+\s[PTGMK]?B$/gm)
59+
}
60+
3361
exports.expectIsBandwidth = (err, stats) => {
3462
expect(err).to.not.exist()
3563
expect(stats).to.exist()

0 commit comments

Comments
 (0)