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

ID impl + tests (core+api+cli) #44

Merged
merged 3 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
"main": "src/index.js",
"scripts": {
"lint": "standard",
"coverage": "istanbul cover --print both -- _mocha tests/test-*/test-*.js",
"test": "mocha tests/test-*/test-*.js"
"coverage": "istanbul cover --print both -- _mocha tests/test-*/index.js",
"test": "mocha tests/test-*/index.js",
"test:core": "mocha tests/test-core/index.js",
"test:cli": "mocha tests/test-cli/index.js",
"test:cli-offline": "mocha tests/test-cli-offline/index.js"
},
"pre-commit": [
"lint",
Expand Down
6 changes: 3 additions & 3 deletions src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.start = callback => {
})

// load routes
require('./routes/version.js')
require('./routes')

server.start(err => {
if (err) { return callback(err) }
Expand All @@ -35,6 +35,6 @@ exports.start = callback => {
})
}

exports.stop = () => {

exports.stop = callback => {
exports.server.stop(callback)
}
14 changes: 14 additions & 0 deletions src/http-api/resources/id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

const ipfs = require('./../index.js').ipfs
const boom = require('boom')

exports = module.exports

exports.get = (request, reply) => {
ipfs.id((err, id) => {
if (err) { return reply(boom.badRequest(err)) }
return reply(id)
})
}

1 change: 1 addition & 0 deletions src/http-api/resources/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
exports.version = require('./version')
exports.id = require('./id')
10 changes: 10 additions & 0 deletions src/http-api/routes/id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const server = require('./../index.js').server
const resources = require('./../resources')

server.route({
method: 'GET',
path: '/api/v0/id',
handler: resources.id.get
})
2 changes: 2 additions & 0 deletions src/http-api/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('./version')
require('./id')
2 changes: 1 addition & 1 deletion src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function IPFS () {
repo.exists((err, exists) => {
if (err) { return callback(err) }

repo.config.read((err, config) => {
repo.config.get((err, config) => {
if (err) {
return callback(err)
}
Expand Down
35 changes: 35 additions & 0 deletions tests/test-api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* globals describe, before, after */

'use strict'

const fs = require('fs')
const expect = require('chai').expect
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
const api = require('../../src/http-api')

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

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

var tests = fs.readdirSync(__dirname)
tests.filter(file => {
if (file === 'index.js') {
return false
} else {
return true
}
}).forEach(file => {
require('./' + file)
})
})
26 changes: 26 additions & 0 deletions tests/test-api/test-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* globals describe, it */

'use strict'

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

describe('id', function () {
it('get the id', done => {
api.server.inject({
method: 'GET',
url: '/api/v0/id'
}, res => {
expect(res.result).to.deep.equal({ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',
PublicKey: '',
Addresses:
{ Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],
API: '/ip4/127.0.0.1/tcp/5001',
Gateway: '/ip4/127.0.0.1/tcp/8080' },
AgentVersion: 'js-ipfs',
ProtocolVersion: '9000'
})
done()
})
})
})
19 changes: 7 additions & 12 deletions tests/test-api/test-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
'use strict'

const expect = require('chai').expect

process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
const api = require('../../src/http-api')

describe('api: version', function () {
describe('version', function () {
it('get the version', done => {
api.start(err => {
expect(err).to.not.exist
api.server.inject({
method: 'GET',
url: '/api/v0/version'
}, res => {
expect(res.result).to.equal('0.4.0-dev')
done()
})
api.server.inject({
method: 'GET',
url: '/api/v0/version'
}, res => {
expect(res.result).to.equal('0.4.0-dev')
done()
})
})
})
18 changes: 18 additions & 0 deletions tests/test-cli-offline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* globals describe */

'use strict'

var fs = require('fs')

describe('cli-offline', () => {
var tests = fs.readdirSync(__dirname)
tests.filter(file => {
if (file === 'index.js') {
return false
} else {
return true
}
}).forEach(file => {
require('./' + file)
})
})
34 changes: 34 additions & 0 deletions tests/test-cli-offline/test-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* globals describe, it */

'use strict'

const expect = require('chai').expect
const nexpect = require('nexpect')

describe('id', () => {
it('get the id', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'])
.run((err, stdout, exitcode) => {
var expected = [ '{ ID: \'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A\',',
' PublicKey: \'\',',
' Addresses: ',
' { Swarm: [ \'/ip4/0.0.0.0/tcp/4001\', \'/ip6/::/tcp/4001\' ],',
' API: \'/ip4/127.0.0.1/tcp/5001\',',
' Gateway: \'/ip4/127.0.0.1/tcp/8080\' },',
' AgentVersion: \'js-ipfs\',',
' ProtocolVersion: \'9000\' }' ]

expect(stdout[0]).to.equal(expected[0])
expect(stdout[1]).to.equal(expected[1])
expect(stdout[2]).to.equal(expected[2])
expect(stdout[3]).to.equal(expected[3])
expect(stdout[4]).to.equal(expected[4])
expect(stdout[5]).to.equal(expected[5])
expect(stdout[6]).to.equal(expected[6])
expect(stdout[7]).to.equal(expected[7])
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})
2 changes: 1 addition & 1 deletion tests/test-cli-offline/test-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const expect = require('chai').expect
const nexpect = require('nexpect')

describe('cli-offline: version', () => {
describe('version', () => {
it('get the version', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
.expect('0.4.0-dev')
Expand Down
18 changes: 18 additions & 0 deletions tests/test-cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* globals describe */

'use strict'

var fs = require('fs')

describe('cli', () => {
var tests = fs.readdirSync(__dirname)
tests.filter(file => {
if (file === 'index.js') {
return false
} else {
return true
}
}).forEach(file => {
require('./' + file)
})
})
34 changes: 34 additions & 0 deletions tests/test-cli/test-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* globals describe, it */

'use strict'

const expect = require('chai').expect
const nexpect = require('nexpect')

describe('id', () => {
it('get the id', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'])
.run((err, stdout, exitcode) => {
var expected = [ '{ ID: \'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A\',',
' PublicKey: \'\',',
' Addresses: ',
' { Swarm: [ \'/ip4/0.0.0.0/tcp/4001\', \'/ip6/::/tcp/4001\' ],',
' API: \'/ip4/127.0.0.1/tcp/5001\',',
' Gateway: \'/ip4/127.0.0.1/tcp/8080\' },',
' AgentVersion: \'js-ipfs\',',
' ProtocolVersion: \'9000\' }' ]

expect(stdout[0]).to.equal(expected[0])
expect(stdout[1]).to.equal(expected[1])
expect(stdout[2]).to.equal(expected[2])
expect(stdout[3]).to.equal(expected[3])
expect(stdout[4]).to.equal(expected[4])
expect(stdout[5]).to.equal(expected[5])
expect(stdout[6]).to.equal(expected[6])
expect(stdout[7]).to.equal(expected[7])
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})
3 changes: 2 additions & 1 deletion tests/test-cli/test-version.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* globals describe, it */

'use strict'

const expect = require('chai').expect
const nexpect = require('nexpect')

describe('cli: version', () => {
describe('version', () => {
it('get the version', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
.expect('0.4.0-dev')
Expand Down
18 changes: 18 additions & 0 deletions tests/test-core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* globals describe */

'use strict'

var fs = require('fs')

describe('core', () => {
var tests = fs.readdirSync(__dirname)
tests.filter(file => {
if (file === 'index.js') {
return false
} else {
return true
}
}).forEach(file => {
require('./' + file)
})
})
27 changes: 27 additions & 0 deletions tests/test-core/test-id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* globals describe, it */

'use strict'

const expect = require('chai').expect

process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
const IPFS = require('../../src/ipfs-core')

describe('id', () => {
it('get id', done => {
let ipfs = new IPFS()
ipfs.id((err, id) => {
expect(err).to.not.exist
expect(id).to.deep.equal({ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',
PublicKey: '',
Addresses:
{ Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],
API: '/ip4/127.0.0.1/tcp/5001',
Gateway: '/ip4/127.0.0.1/tcp/8080' },
AgentVersion: 'js-ipfs',
ProtocolVersion: '9000'
})
done()
})
})
})
2 changes: 1 addition & 1 deletion tests/test-core/test-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const expect = require('chai').expect
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
const IPFS = require('../../src/ipfs-core')

describe('core: version', () => {
describe('version', () => {
it('get version', done => {
let ipfs = new IPFS()
ipfs.version((err, version) => {
Expand Down