|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const FactoryClient = require('./ipfs-factory/client') |
| 5 | +const chai = require('chai') |
| 6 | +const dirtyChai = require('dirty-chai') |
| 7 | +const expect = chai.expect |
| 8 | +chai.use(dirtyChai) |
| 9 | + |
| 10 | +describe('stats', function () { |
| 11 | + this.timeout(50 * 1000) // slow CI |
| 12 | + |
| 13 | + let ipfs |
| 14 | + let fc |
| 15 | + |
| 16 | + before((done) => { |
| 17 | + fc = new FactoryClient() |
| 18 | + fc.spawnNode((err, node) => { |
| 19 | + expect(err).to.not.exist() |
| 20 | + ipfs = node |
| 21 | + done() |
| 22 | + }) |
| 23 | + }) |
| 24 | + |
| 25 | + after((done) => { |
| 26 | + fc.dismantle(done) |
| 27 | + }) |
| 28 | + |
| 29 | + describe('Callback API', () => { |
| 30 | + it('.stats.bitswap', (done) => { |
| 31 | + ipfs.stats.bitswap((err, res) => { |
| 32 | + expect(err).to.not.exist() |
| 33 | + expect(res).to.exist() |
| 34 | + expect(res).to.have.a.property('ProvideBufLen') |
| 35 | + expect(res).to.have.a.property('Wantlist') |
| 36 | + expect(res).to.have.a.property('Peers') |
| 37 | + expect(res).to.have.a.property('BlocksReceived') |
| 38 | + expect(res).to.have.a.property('DataReceived') |
| 39 | + expect(res).to.have.a.property('BlocksSent') |
| 40 | + expect(res).to.have.a.property('DataSent') |
| 41 | + expect(res).to.have.a.property('DupBlksReceived') |
| 42 | + expect(res).to.have.a.property('DupDataReceived') |
| 43 | + done() |
| 44 | + }) |
| 45 | + }) |
| 46 | + |
| 47 | + it('.stats.bw', (done) => { |
| 48 | + ipfs.stats.bw((err, res) => { |
| 49 | + expect(err).to.not.exist() |
| 50 | + expect(res).to.exist() |
| 51 | + expect(res).to.have.a.property('TotalIn') |
| 52 | + expect(res).to.have.a.property('TotalOut') |
| 53 | + expect(res).to.have.a.property('RateIn') |
| 54 | + expect(res).to.have.a.property('RateOut') |
| 55 | + done() |
| 56 | + }) |
| 57 | + }) |
| 58 | + |
| 59 | + it('.stats.repo', (done) => { |
| 60 | + ipfs.stats.repo((err, res) => { |
| 61 | + expect(err).to.not.exist() |
| 62 | + expect(res).to.exist() |
| 63 | + expect(res).to.have.a.property('NumObjects') |
| 64 | + expect(res).to.have.a.property('RepoSize') |
| 65 | + expect(res).to.have.a.property('RepoPath') |
| 66 | + expect(res).to.have.a.property('Version') |
| 67 | + expect(res).to.have.a.property('StorageMax') |
| 68 | + done() |
| 69 | + }) |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + describe('Promise API', () => { |
| 74 | + it('.stats.bw', () => { |
| 75 | + return ipfs.stats.bw() |
| 76 | + .then((res) => { |
| 77 | + expect(res).to.exist() |
| 78 | + expect(res).to.have.a.property('TotalIn') |
| 79 | + expect(res).to.have.a.property('TotalOut') |
| 80 | + expect(res).to.have.a.property('RateIn') |
| 81 | + expect(res).to.have.a.property('RateOut') |
| 82 | + }) |
| 83 | + }) |
| 84 | + |
| 85 | + it('.stats.repo', () => { |
| 86 | + return ipfs.stats.repo() |
| 87 | + .then((res) => { |
| 88 | + expect(res).to.exist() |
| 89 | + expect(res).to.have.a.property('NumObjects') |
| 90 | + expect(res).to.have.a.property('RepoSize') |
| 91 | + expect(res).to.have.a.property('RepoPath') |
| 92 | + expect(res).to.have.a.property('Version') |
| 93 | + expect(res).to.have.a.property('StorageMax') |
| 94 | + }) |
| 95 | + }) |
| 96 | + |
| 97 | + it('.stats.bitswap', () => { |
| 98 | + return ipfs.stats.bitswap() |
| 99 | + .then((res) => { |
| 100 | + expect(res).to.exist() |
| 101 | + expect(res).to.have.a.property('ProvideBufLen') |
| 102 | + expect(res).to.have.a.property('Wantlist') |
| 103 | + expect(res).to.have.a.property('Peers') |
| 104 | + expect(res).to.have.a.property('BlocksReceived') |
| 105 | + expect(res).to.have.a.property('DataReceived') |
| 106 | + expect(res).to.have.a.property('BlocksSent') |
| 107 | + expect(res).to.have.a.property('DataSent') |
| 108 | + expect(res).to.have.a.property('DupBlksReceived') |
| 109 | + expect(res).to.have.a.property('DupDataReceived') |
| 110 | + }) |
| 111 | + }) |
| 112 | + }) |
| 113 | +}) |
0 commit comments