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

feat: ipfs version flags + ipfs repo version #1181

Merged
merged 11 commits into from
Jan 25, 2018
Prev Previous commit
Next Next commit
Add tests for , found a bug, fixed it by flattening response of http …
…api repo/version.
JonKrone committed Jan 22, 2018
commit 84b5641f454b9bc8ffba5c67f03c7c95b10ab67c
4 changes: 2 additions & 2 deletions src/cli/commands/repo/version.js
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ module.exports = {
builder: {},

handler (argv) {
argv.ipfs.repo.version((err, resp) => {
argv.ipfs.repo.version((err, version) => {
if (err) {
throw err
}
print(resp.version)
print(version)
})
}
}
4 changes: 1 addition & 3 deletions src/http/api/resources/repo.js
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ exports.version = (request, reply) => {
return reply(boom.badRequest(err))
}

reply({
version: version
})
reply(version)
})
}
11 changes: 10 additions & 1 deletion test/cli/repo.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
/* eslint-env mocha */
'use strict'

const fs = require('fs')
const path = require('path')
const expect = require('chai').expect
const runOnAndOff = require('../utils/on-and-off')

function getRepoVersion(ipfs) {
const versionPath = path.join(ipfs.repoPath, 'version')
return String(fs.readFileSync(versionPath))
}

describe('repo', () => runOnAndOff((thing) => {
let ipfs
let repoVersion

before(() => {
ipfs = thing.ipfs
repoVersion = getRepoVersion(ipfs)
})

it('get the repo version', () => {
return ipfs('repo version').then((out) => {
expect(out).to.include(`\n`)
expect(out).to.eql(`${repoVersion}\n`)
})
})
}))
20 changes: 14 additions & 6 deletions test/cli/version.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
/* eslint-env mocha */
'use strict'

const fs = require('fs')
const path = require('path')
const expect = require('chai').expect
const pkgversion = require('../../package.json').version
const runOnAndOff = require('../utils/on-and-off')

function getRepoVersion(ipfs) {
const versionPath = path.join(ipfs.repoPath, 'version')
return String(fs.readFileSync(versionPath))
}

describe('version', () => runOnAndOff((thing) => {
let ipfs
let repoVersion

before(() => {
ipfs = thing.ipfs
repoVersion = getRepoVersion(ipfs)
})

it('get the version', () => {
@@ -33,19 +42,18 @@ describe('version', () => runOnAndOff((thing) => {
})

it('handles --all', () => {
// NOTE does not confirm repo version number
return ipfs('version --all').then(out =>
expect(out).to.include(
`js-ipfs version: ${pkgversion}-
Repo version: `
Repo version: ${repoVersion}
`
)
)
})

it('handles --repo', () => {
// TODO how can we get the repo version number to confirm test is correct?
return ipfs('version --repo').then(out =>
expect(out).to.include('\n') // printed something
)
return ipfs('version --repo').then(out => {
expect(out).to.eql(`${repoVersion}\n`)
})
})
}))