From 09885805c3db4d34c0c44eca64333b9e127849e0 Mon Sep 17 00:00:00 2001 From: Francisco Baio Dias Date: Sun, 13 Mar 2016 18:10:02 +0000 Subject: [PATCH] Add api running test for ipfs version & fix #70 --- src/cli/commands/version.js | 13 +++++++++---- src/http-api/resources/version.js | 3 +-- tests/test-cli/test-version.js | 27 +++++++++++++++++++++++++-- tests/test-http-api/test-version.js | 3 +-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 337c2f55fa..09375cf4b0 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -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') @@ -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) }) } }) diff --git a/src/http-api/resources/version.js b/src/http-api/resources/version.js index 9f14c80160..f863cb117c 100644 --- a/src/http-api/resources/version.js +++ b/src/http-api/resources/version.js @@ -18,8 +18,7 @@ exports.get = (request, reply) => { Version: ipfsVersion, Commit: '', Repo: repoVersion - }).header('Transfer-Encoding', 'chunked') - .type('application/json') + }) }) }) } diff --git a/tests/test-cli/test-version.js b/tests/test-cli/test-version.js index 5e5083c884..821ee19678 100644 --- a/tests/test-cli/test-version.js +++ b/tests/test-cli/test-version.js @@ -2,14 +2,15 @@ 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() }) @@ -17,6 +18,28 @@ describe('version', () => { }) 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() + }) + }) }) }) diff --git a/tests/test-http-api/test-version.js b/tests/test-http-api/test-version.js index 57fed030ba..effe5ff9db 100644 --- a/tests/test-http-api/test-version.js +++ b/tests/test-http-api/test-version.js @@ -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')