From 6c81f9a9853d3a681c2e78a848da44a511939e7b Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 13 Jan 2016 17:34:16 +0100 Subject: [PATCH 1/2] core: config.show config.replace --- src/cli/commands/add.js | 3 +- src/cli/commands/bootstrap/list.js | 4 +- src/cli/commands/commands.js | 3 +- src/cli/commands/dns.js | 3 +- src/cli/commands/get.js | 3 +- src/cli/commands/init.js | 5 +- src/cli/commands/ls.js | 3 +- src/cli/commands/mount.js | 3 +- src/cli/commands/ping.js | 3 +- src/cli/commands/refs.js | 3 +- src/cli/commands/repo/gc.js | 3 +- src/cli/commands/repo/init.js | 3 +- src/cli/commands/resolve.js | 3 +- src/cli/commands/update.js | 3 +- src/http-api/resources/id.js | 1 - src/http-api/resources/version.js | 1 - src/ipfs-core/index.js | 14 ++++ tests/test-api/test-id.js | 7 +- tests/test-cli-offline/test-bootstrap.js | 56 +++++++------- tests/test-cli-offline/test-id.js | 42 +++++------ tests/test-cli-offline/test-version.js | 12 +-- tests/test-cli/test-id.js | 42 +++++------ tests/test-cli/test-version.js | 12 +-- tests/test-core/test-config.js | 94 ++++++++++++++++++++++++ tests/test-core/test-id.js | 7 +- 25 files changed, 224 insertions(+), 109 deletions(-) create mode 100644 tests/test-core/test-config.js diff --git a/src/cli/commands/add.js b/src/cli/commands/add.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/add.js +++ b/src/cli/commands/add.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/bootstrap/list.js b/src/cli/commands/bootstrap/list.js index 9f52b092a4..1a09b46522 100644 --- a/src/cli/commands/bootstrap/list.js +++ b/src/cli/commands/bootstrap/list.js @@ -15,7 +15,9 @@ module.exports = Command.extend({ var node = new IPFS() node.bootstrap.list((err, list) => { if (err) { return log.error(err) } - list.forEach(node => { console.log(node) }) + list.forEach(node => { + console.log(node) + }) }) } }) diff --git a/src/cli/commands/commands.js b/src/cli/commands/commands.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/commands.js +++ b/src/cli/commands/commands.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/get.js b/src/cli/commands/get.js index cb1b1d172f..0597eb07f7 100644 --- a/src/cli/commands/get.js +++ b/src/cli/commands/get.js @@ -3,5 +3,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index 7c0e39e3e9..4ed58ef01f 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -20,9 +20,10 @@ module.exports = Command.extend({ 'empty-repo': { alias: 'e', type: 'boolean', - desc: 'Don\'t add and pin help files to the local storage' + desc: "Don't add and pin help files to the local storage" } }, - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/mount.js b/src/cli/commands/mount.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/mount.js +++ b/src/cli/commands/mount.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/ping.js b/src/cli/commands/ping.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/ping.js +++ b/src/cli/commands/ping.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/refs.js b/src/cli/commands/refs.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/refs.js +++ b/src/cli/commands/refs.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/repo/gc.js b/src/cli/commands/repo/gc.js index a85298d461..6900dc7727 100644 --- a/src/cli/commands/repo/gc.js +++ b/src/cli/commands/repo/gc.js @@ -7,6 +7,5 @@ module.exports = Command.extend({ options: { }, - run: function (name) { - } + run: function (name) {} }) diff --git a/src/cli/commands/repo/init.js b/src/cli/commands/repo/init.js index a85298d461..6900dc7727 100644 --- a/src/cli/commands/repo/init.js +++ b/src/cli/commands/repo/init.js @@ -7,6 +7,5 @@ module.exports = Command.extend({ options: { }, - run: function (name) { - } + run: function (name) {} }) diff --git a/src/cli/commands/resolve.js b/src/cli/commands/resolve.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/resolve.js +++ b/src/cli/commands/resolve.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/cli/commands/update.js b/src/cli/commands/update.js index 160f94228c..b86b5708e4 100644 --- a/src/cli/commands/update.js +++ b/src/cli/commands/update.js @@ -5,5 +5,6 @@ const Command = require('ronin').Command module.exports = Command.extend({ desc: '', - run: name => {} + run: name => { + } }) diff --git a/src/http-api/resources/id.js b/src/http-api/resources/id.js index 0f96aa87a1..79b39759e4 100644 --- a/src/http-api/resources/id.js +++ b/src/http-api/resources/id.js @@ -11,4 +11,3 @@ exports.get = (request, reply) => { return reply(id) }) } - diff --git a/src/http-api/resources/version.js b/src/http-api/resources/version.js index d598e8882e..f08a7e190d 100644 --- a/src/http-api/resources/version.js +++ b/src/http-api/resources/version.js @@ -11,4 +11,3 @@ exports.get = (request, reply) => { return reply(version) }) } - diff --git a/src/ipfs-core/index.js b/src/ipfs-core/index.js index 697854894e..233acc3909 100644 --- a/src/ipfs-core/index.js +++ b/src/ipfs-core/index.js @@ -110,4 +110,18 @@ function IPFS () { }) } } + + this.config = { + // cli only feature built with show and replace + // edit: (callback) => {}, + replace: (config, callback) => { + repo.config.set(config, callback) + }, + show: callback => { + repo.config.get((err, config) => { + if (err) { return callback(err) } + callback(null, config) + }) + } + } } diff --git a/tests/test-api/test-id.js b/tests/test-api/test-id.js index 3825d3c8c3..aff4f828da 100644 --- a/tests/test-api/test-id.js +++ b/tests/test-api/test-id.js @@ -13,10 +13,9 @@ describe('id', function () { }, 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' }, + 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' }) diff --git a/tests/test-cli-offline/test-bootstrap.js b/tests/test-cli-offline/test-bootstrap.js index f23dca6245..bf7002cf1a 100644 --- a/tests/test-cli-offline/test-bootstrap.js +++ b/tests/test-cli-offline/test-bootstrap.js @@ -33,43 +33,43 @@ describe('bootstrap', () => { it('list the bootstrap nodes', done => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) - .run((err, stdout, exitcode) => { - expect(stdout).to.deep.equal(defaultList) - expect(err).to.not.exist - expect(exitcode).to.equal(0) - done() - }) + .run((err, stdout, exitcode) => { + expect(stdout).to.deep.equal(defaultList) + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) }) it('add another bootstrap node', done => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'add', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT']) - .run((err, stdout, exitcode) => { - expect(err).to.not.exist - expect(exitcode).to.equal(0) + .run((err, stdout, exitcode) => { + expect(err).to.not.exist + expect(exitcode).to.equal(0) - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) - .run((err, stdout, exitcode) => { - expect(stdout).to.deep.equal(updatedList) - expect(err).to.not.exist - expect(exitcode).to.equal(0) - done() - }) - }) + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) + .run((err, stdout, exitcode) => { + expect(stdout).to.deep.equal(updatedList) + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) }) it('rm a bootstrap node', done => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'rm', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT']) - .run((err, stdout, exitcode) => { - expect(err).to.not.exist - expect(exitcode).to.equal(0) + .run((err, stdout, exitcode) => { + expect(err).to.not.exist + expect(exitcode).to.equal(0) - nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) - .run((err, stdout, exitcode) => { - expect(stdout).to.deep.equal(defaultList) - expect(err).to.not.exist - expect(exitcode).to.equal(0) - done() - }) - }) + nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list']) + .run((err, stdout, exitcode) => { + expect(stdout).to.deep.equal(defaultList) + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) + }) }) }) diff --git a/tests/test-cli-offline/test-id.js b/tests/test-cli-offline/test-id.js index ca89094d8f..83c1c7d960 100644 --- a/tests/test-cli-offline/test-id.js +++ b/tests/test-cli-offline/test-id.js @@ -8,27 +8,27 @@ 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\' }' ] + .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() - }) + 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() + }) }) }) diff --git a/tests/test-cli-offline/test-version.js b/tests/test-cli-offline/test-version.js index cc41a4d4d1..f6be02c148 100644 --- a/tests/test-cli-offline/test-version.js +++ b/tests/test-cli-offline/test-version.js @@ -8,11 +8,11 @@ const nexpect = require('nexpect') describe('version', () => { 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(exitcode).to.equal(0) - done() - }) + .expect('0.4.0-dev') + .run((err, stdout, exitcode) => { + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) }) }) diff --git a/tests/test-cli/test-id.js b/tests/test-cli/test-id.js index ca89094d8f..83c1c7d960 100644 --- a/tests/test-cli/test-id.js +++ b/tests/test-cli/test-id.js @@ -8,27 +8,27 @@ 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\' }' ] + .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() - }) + 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() + }) }) }) diff --git a/tests/test-cli/test-version.js b/tests/test-cli/test-version.js index cc41a4d4d1..f6be02c148 100644 --- a/tests/test-cli/test-version.js +++ b/tests/test-cli/test-version.js @@ -8,11 +8,11 @@ const nexpect = require('nexpect') describe('version', () => { 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(exitcode).to.equal(0) - done() - }) + .expect('0.4.0-dev') + .run((err, stdout, exitcode) => { + expect(err).to.not.exist + expect(exitcode).to.equal(0) + done() + }) }) }) diff --git a/tests/test-core/test-config.js b/tests/test-core/test-config.js new file mode 100644 index 0000000000..7e6a61f985 --- /dev/null +++ b/tests/test-core/test-config.js @@ -0,0 +1,94 @@ +/* globals describe, it */ + +'use strict' + +const expect = require('chai').expect +const IPFS = require('../../src/ipfs-core') + +describe('config', () => { + var defaultConfig = { + Identity: { + PeerID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', + PrivKey: 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw==' }, + Datastore: { Type: '', + Path: '', + StorageMax: '', + StorageGCWatermark: 0, + GCPeriod: '', + Params: null, + NoSync: false }, + 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' }, + Mounts: { IPFS: '/ipfs', IPNS: '/ipns', FuseAllowOther: false }, + Version: { Current: '0.4.0-dev', + Check: 'error', + CheckDate: '0001-01-01T00:00:00Z', + CheckPeriod: '172800000000000', + AutoUpdate: 'minor' }, + Discovery: { MDNS: { Enabled: true, Interval: 10 } }, + Ipns: { RepublishPeriod: '', + RecordLifetime: '', + ResolveCacheSize: 128 }, + Bootstrap: [ '/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ', + '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z', + '/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM', + '/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm', + '/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu', + '/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', + '/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', + '/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', + '/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' ], + Tour: { Last: '' }, + Gateway: { HTTPHeaders: null, RootRedirect: '', Writable: false }, + SupernodeRouting: { + Servers: [ + '/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U', + '/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6', + '/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH', + '/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP', + '/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R', + '/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4', + '/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v', + '/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN' + ] + }, + API: { + HTTPHeaders: null + }, + Swarm: { + AddrFilters: null + }, + Log: { + MaxSizeMB: 250, + MaxBackups: 1, + MaxAgeDays: 0 + } + } + + it('show', done => { + let ipfs = new IPFS() + ipfs.config.show((err, config) => { + expect(err).to.not.exist + expect(config).to.deep.equal(defaultConfig) + done() + }) + }) + + it.skip('replace', done => { + let ipfs = new IPFS() + ipfs.config((err, config) => { + expect(err).to.not.exist + done() + }) + }) + + // cli only feature built with show and replace + // it.skip('edit', done => { + // let ipfs = new IPFS() + // ipfs.config((err, config) => { + // expect(err).to.not.exist + // done() + // }) + // }) +}) diff --git a/tests/test-core/test-id.js b/tests/test-core/test-id.js index 76d3a9db93..7e99577030 100644 --- a/tests/test-core/test-id.js +++ b/tests/test-core/test-id.js @@ -14,10 +14,9 @@ describe('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' }, + 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' }) From 64154d65e65ffad181974b94a40f90cbcfa7ac48 Mon Sep 17 00:00:00 2001 From: David Dias Date: Thu, 14 Jan 2016 14:56:02 +0000 Subject: [PATCH 2/2] tests and cli stuff --- src/cli/commands/config/edit.js | 36 ++++++++++++++++++++++++++++++ src/cli/commands/config/replace.js | 25 +++++++++++++++++++++ src/cli/commands/config/show.js | 22 ++++++++++++++++++ tests/test-core/test-config.js | 13 ++++++++--- 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/cli/commands/config/edit.js create mode 100644 src/cli/commands/config/replace.js create mode 100644 src/cli/commands/config/show.js diff --git a/src/cli/commands/config/edit.js b/src/cli/commands/config/edit.js new file mode 100644 index 0000000000..ea49ae4cad --- /dev/null +++ b/src/cli/commands/config/edit.js @@ -0,0 +1,36 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const log = debug('cli:version') +log.error = debug('cli:version:error') + +module.exports = Command.extend({ + desc: 'Shows IPFS version information', + + options: { + number: { + alias: 'n', + type: 'boolean', + default: false + }, + commit: { + type: 'boolean', + default: false + }, + repo: { + type: 'boolean', + default: false + } + }, + + run: (name) => { + var node = new IPFS() + node.version((err, version) => { + if (err) { return log.error(err) } + + console.log(version) + }) + } +}) diff --git a/src/cli/commands/config/replace.js b/src/cli/commands/config/replace.js new file mode 100644 index 0000000000..d2b94d096a --- /dev/null +++ b/src/cli/commands/config/replace.js @@ -0,0 +1,25 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const path = require('path') +const log = debug('cli:version') +log.error = debug('cli:version:error') + +module.exports = Command.extend({ + desc: 'Replaces the config with ', + + options: {}, + + run: (configPath) => { + var node = new IPFS() + var config = require(path.resolve(process.cwd(), configPath)) + + node.config.replace(config, (err, version) => { + if (err) { return log.error(err) } + + console.log(version) + }) + } +}) diff --git a/src/cli/commands/config/show.js b/src/cli/commands/config/show.js new file mode 100644 index 0000000000..f5cb923cdf --- /dev/null +++ b/src/cli/commands/config/show.js @@ -0,0 +1,22 @@ +'use strict' + +const Command = require('ronin').Command +const IPFS = require('../../../ipfs-core') +const debug = require('debug') +const log = debug('cli:version') +log.error = debug('cli:version:error') + +module.exports = Command.extend({ + desc: 'Outputs the content of the config file', + + options: {}, + + run: () => { + var node = new IPFS() + node.config.show((err, config) => { + if (err) { return log.error(err) } + + console.log(JSON.stringify(config, null, 4)) + }) + } +}) diff --git a/tests/test-core/test-config.js b/tests/test-core/test-config.js index 7e6a61f985..3222bc85c1 100644 --- a/tests/test-core/test-config.js +++ b/tests/test-core/test-config.js @@ -75,11 +75,18 @@ describe('config', () => { }) }) - it.skip('replace', done => { + it('replace', done => { let ipfs = new IPFS() - ipfs.config((err, config) => { + ipfs.config.replace({}, err => { expect(err).to.not.exist - done() + ipfs.config.show((err, config) => { + expect(err).to.not.exist + expect(config).to.deep.equal({}) + ipfs.config.replace(defaultConfig, err => { + expect(err).to.not.exist + done() + }) + }) }) })