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

fix: stats not implemented on jsipfs #209

Merged
merged 3 commits into from
Jan 25, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions src/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chai.use(dirtyChai)
module.exports = (common) => {
describe('.stats', () => {
let ipfs
let withGo

before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
Expand All @@ -22,7 +23,11 @@ module.exports = (common) => {
factory.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
node.id((err, id) => {
expect(err).to.not.exist()
withGo = id.agentVersion.startsWith('go-ipfs')
done()
})
})
})
})
Expand All @@ -32,6 +37,11 @@ module.exports = (common) => {
})

it('.bitswap', (done) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return done()
}

ipfs.stats.bitswap((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
Expand All @@ -49,6 +59,11 @@ module.exports = (common) => {
})

it('.bitswap Promise', () => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return
}

return ipfs.stats.bitswap().then((res) => {
expect(res).to.exist()
expect(res).to.have.a.property('provideBufLen')
Expand All @@ -64,6 +79,11 @@ module.exports = (common) => {
})

it('.bw', (done) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return done()
}

ipfs.stats.bw((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
Expand All @@ -76,7 +96,12 @@ module.exports = (common) => {
})

it('.bw Promise', () => {
return ipfs.stats.bw().then((res) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return
}

ipfs.stats.bw().then((res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hacdias you should add a return here. Otherwise the test will pass before the call happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOPS! Sorry. fixed!

expect(res).to.exist()
expect(res).to.have.a.property('totalIn')
expect(res).to.have.a.property('totalOut')
Expand All @@ -86,6 +111,11 @@ module.exports = (common) => {
})

it('.repo', (done) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return done()
}

ipfs.stats.repo((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
Expand All @@ -99,7 +129,12 @@ module.exports = (common) => {
})

it('.repo Promise', () => {
return ipfs.stats.repo().then((res) => {
if (!withGo) {
console.log('Not supported in js-ipfs yet')
return
}

ipfs.stats.repo().then((res) => {
expect(res).to.exist()
expect(res).to.have.a.property('numObjects')
expect(res).to.have.a.property('repoSize')
Expand Down