Skip to content

Commit 0988580

Browse files
fbaiodiashackergrrl
authored andcommitted
Add api running test for ipfs version & fix ipfs#70
1 parent 3d6027a commit 0988580

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/cli/commands/version.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const Command = require('ronin').Command
4-
const IPFS = require('../../ipfs-core')
4+
const utils = require('../utils')
55
const debug = require('debug')
66
const log = debug('cli:version')
77
log.error = debug('cli:version:error')
@@ -26,11 +26,16 @@ module.exports = Command.extend({
2626
},
2727

2828
run: (name) => {
29-
var node = new IPFS()
30-
node.version((err, version) => {
29+
var ipfs = utils.getIPFS()
30+
ipfs.version((err, version) => {
3131
if (err) { return log.error(err) }
3232

33-
console.log(version)
33+
if (typeof version === 'object') { // js-ipfs-api output
34+
console.log('ipfs version', version.Version)
35+
return
36+
}
37+
38+
console.log('ipfs version', version)
3439
})
3540
}
3641
})

src/http-api/resources/version.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ exports.get = (request, reply) => {
1818
Version: ipfsVersion,
1919
Commit: '',
2020
Repo: repoVersion
21-
}).header('Transfer-Encoding', 'chunked')
22-
.type('application/json')
21+
})
2322
})
2423
})
2524
}

tests/test-cli/test-version.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,44 @@
22

33
const expect = require('chai').expect
44
const nexpect = require('nexpect')
5+
const httpAPI = require('../../src/http-api')
56

67
describe('version', () => {
78
describe('api offline', () => {
89
it('get the version', (done) => {
910
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
10-
.expect('0.4.0-dev')
1111
.run((err, stdout, exitcode) => {
1212
expect(err).to.not.exist
13+
expect(stdout[0]).to.equal('ipfs version 0.4.0-dev')
1314
expect(exitcode).to.equal(0)
1415
done()
1516
})
1617
})
1718
})
1819

1920
describe('api running', () => {
20-
// TODO
21+
before((done) => {
22+
httpAPI.start((err) => {
23+
expect(err).to.not.exist
24+
done()
25+
})
26+
})
27+
28+
after((done) => {
29+
httpAPI.stop((err) => {
30+
expect(err).to.not.exist
31+
done()
32+
})
33+
})
34+
35+
it('get the version', (done) => {
36+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
37+
.run((err, stdout, exitcode) => {
38+
expect(err).to.not.exist
39+
expect(exitcode).to.equal(0)
40+
expect(stdout[0]).to.equal('ipfs version 0.4.0-dev')
41+
done()
42+
})
43+
})
2144
})
2245
})

tests/test-http-api/test-version.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ describe('version', () => {
3535
done()
3636
})
3737

38-
// TODO fix: only fails on travis
39-
it.skip('get the version', (done) => {
38+
it('get the version', (done) => {
4039
ctl.version((err, result) => {
4140
expect(err).to.not.exist
4241
expect(result).to.have.a.property('Version')

0 commit comments

Comments
 (0)