From c6aca094808708facbf38dee0aca441a44d6f62f Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Fri, 8 Nov 2019 15:58:50 +0000 Subject: [PATCH 1/2] test: add human readable repo stats test --- src/repo/stat.js | 8 +++++++- src/stats/utils.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/repo/stat.js b/src/repo/stat.js index d313a9998..bb6b39bc4 100644 --- a/src/repo/stat.js +++ b/src/repo/stat.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const { expectIsRepo } = require('../stats/utils') +const { expectIsRepo, expectIsRepoHumanized } = require('../stats/utils') const { getDescribe, getIt, expect } = require('../utils/mocha') module.exports = (createCommon, options) => { @@ -41,5 +41,11 @@ module.exports = (createCommon, options) => { expectIsRepo(null, res) }) }) + + it('should get human readable repo stats', async () => { + const res = await ipfs.repo.stat({ human: true }) + + expectIsRepoHumanized(null, res) + }) }) } diff --git a/src/stats/utils.js b/src/stats/utils.js index fd7a1d62a..800cef07f 100644 --- a/src/stats/utils.js +++ b/src/stats/utils.js @@ -57,3 +57,18 @@ exports.expectIsRepo = (err, res) => { expect(res.repoPath).to.be.a('string') expect(res.version).to.be.a('string') } + +exports.expectIsRepoHumanized = (err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + expect(res).to.have.a.property('numObjects') + expect(res).to.have.a.property('repoSize') + expect(res).to.have.a.property('repoPath') + expect(res).to.have.a.property('version') + expect(res).to.have.a.property('storageMax') + expect(res.numObjects).to.be.a('number') + expect(res.repoSize).to.eql('30.1 kB') + expect(res.storageMax).to.eql('9.01 PB') + expect(res.repoPath).to.be.a('string') + expect(res.version).to.be.a('string') +} From c432f7d2818937efb167e24e2f5163e44110ee38 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Thu, 14 Nov 2019 11:13:07 +0000 Subject: [PATCH 2/2] chore: code review changes --- src/repo/stat.js | 14 ++++++++++++-- src/stats/utils.js | 15 --------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/repo/stat.js b/src/repo/stat.js index bb6b39bc4..ef0f8de4d 100644 --- a/src/repo/stat.js +++ b/src/repo/stat.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const { expectIsRepo, expectIsRepoHumanized } = require('../stats/utils') +const { expectIsRepo } = require('../stats/utils') const { getDescribe, getIt, expect } = require('../utils/mocha') module.exports = (createCommon, options) => { @@ -45,7 +45,17 @@ module.exports = (createCommon, options) => { it('should get human readable repo stats', async () => { const res = await ipfs.repo.stat({ human: true }) - expectIsRepoHumanized(null, res) + expect(res).to.exist() + expect(res).to.have.a.property('numObjects') + expect(res).to.have.a.property('repoSize') + expect(res).to.have.a.property('repoPath') + expect(res).to.have.a.property('version') + expect(res).to.have.a.property('storageMax') + expect(res.numObjects).to.be.a('number') + expect(res.repoSize).to.match(/\s.?B$/gm) + expect(res.storageMax).to.match(/\s.?B$/gm) + expect(res.repoPath).to.be.a('string') + expect(res.version).to.be.a('string') }) }) } diff --git a/src/stats/utils.js b/src/stats/utils.js index 800cef07f..fd7a1d62a 100644 --- a/src/stats/utils.js +++ b/src/stats/utils.js @@ -57,18 +57,3 @@ exports.expectIsRepo = (err, res) => { expect(res.repoPath).to.be.a('string') expect(res.version).to.be.a('string') } - -exports.expectIsRepoHumanized = (err, res) => { - expect(err).to.not.exist() - expect(res).to.exist() - expect(res).to.have.a.property('numObjects') - expect(res).to.have.a.property('repoSize') - expect(res).to.have.a.property('repoPath') - expect(res).to.have.a.property('version') - expect(res).to.have.a.property('storageMax') - expect(res.numObjects).to.be.a('number') - expect(res.repoSize).to.eql('30.1 kB') - expect(res.storageMax).to.eql('9.01 PB') - expect(res.repoPath).to.be.a('string') - expect(res.version).to.be.a('string') -}