Skip to content

Commit

Permalink
Add api running test for ipfs version & fix ipfs#70
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias authored and hackergrrl committed Mar 16, 2016
1 parent 3d6027a commit 0988580
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Command = require('ronin').Command
const IPFS = require('../../ipfs-core')
const utils = require('../utils')
const debug = require('debug')
const log = debug('cli:version')
log.error = debug('cli:version:error')
Expand All @@ -26,11 +26,16 @@ module.exports = Command.extend({
},

run: (name) => {
var node = new IPFS()
node.version((err, version) => {
var ipfs = utils.getIPFS()
ipfs.version((err, version) => {
if (err) { return log.error(err) }

console.log(version)
if (typeof version === 'object') { // js-ipfs-api output
console.log('ipfs version', version.Version)
return
}

console.log('ipfs version', version)
})
}
})
3 changes: 1 addition & 2 deletions src/http-api/resources/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ exports.get = (request, reply) => {
Version: ipfsVersion,
Commit: '',
Repo: repoVersion
}).header('Transfer-Encoding', 'chunked')
.type('application/json')
})
})
})
}
27 changes: 25 additions & 2 deletions tests/test-cli/test-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,44 @@

const expect = require('chai').expect
const nexpect = require('nexpect')
const httpAPI = require('../../src/http-api')

describe('version', () => {
describe('api offline', () => {
it('get the version', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
.expect('0.4.0-dev')
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(stdout[0]).to.equal('ipfs version 0.4.0-dev')
expect(exitcode).to.equal(0)
done()
})
})
})

describe('api running', () => {
// TODO
before((done) => {
httpAPI.start((err) => {
expect(err).to.not.exist
done()
})
})

after((done) => {
httpAPI.stop((err) => {
expect(err).to.not.exist
done()
})
})

it('get the version', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
expect(stdout[0]).to.equal('ipfs version 0.4.0-dev')
done()
})
})
})
})
3 changes: 1 addition & 2 deletions tests/test-http-api/test-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ describe('version', () => {
done()
})

// TODO fix: only fails on travis
it.skip('get the version', (done) => {
it('get the version', (done) => {
ctl.version((err, result) => {
expect(err).to.not.exist
expect(result).to.have.a.property('Version')
Expand Down

0 comments on commit 0988580

Please sign in to comment.