diff --git a/gulpfile.js b/gulpfile.js index c3484e169..a9ff11eb5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,12 +2,11 @@ const gulp = require('gulp') -require('./test/setup/spawn-daemons') -require('./test/factory/factory-tasks') +require('./test/ipfs-factory/tasks') -gulp.task('test:node:before', ['daemons:start', 'factory:start']) -gulp.task('test:node:after', ['daemons:stop', 'factory:stop']) -gulp.task('test:browser:before', ['daemons:start', 'factory:start']) -gulp.task('test:browser:after', ['daemons:stop', 'factory:stop']) +gulp.task('test:node:before', ['factory:start']) +gulp.task('test:node:after', ['factory:stop']) +gulp.task('test:browser:before', ['factory:start']) +gulp.task('test:browser:after', ['factory:stop']) require('aegir/gulp')(gulp) diff --git a/package.json b/package.json index 9afe2fdbb..5b14f1538 100644 --- a/package.json +++ b/package.json @@ -24,29 +24,30 @@ "dependencies": { "async": "^2.1.4", "bs58": "^4.0.0", + "cids": "^0.4.0", "concat-stream": "^1.6.0", "detect-node": "^2.0.3", "flatmap": "0.0.3", "glob": "^7.1.1", "glob-escape": "0.0.2", - "ipfs-block": "^0.5.1", - "ipfs-unixfs": "^0.1.8", - "ipld-dag-pb": "^0.9.3", + "ipfs-block": "^0.5.4", + "ipfs-unixfs": "^0.1.9", + "ipld-dag-pb": "^0.9.4", "is-ipfs": "^0.2.1", "isstream": "^0.1.2", "lru-cache": "^4.0.2", - "multiaddr": "^2.1.1", - "multihashes": "^0.3.1", + "multiaddr": "^2.2.0", + "multihashes": "^0.3.2", "multipart-stream": "^2.0.1", "ndjson": "^1.5.0", "once": "^1.4.0", "peer-id": "^0.8.1", - "peer-info": "^0.8.1", + "peer-info": "^0.8.2", "promisify-es6": "^1.0.2", "pump": "^1.0.2", "qs": "^6.3.0", "readable-stream": "1.1.14", - "stream-http": "^2.5.0", + "stream-http": "^2.6.3", "streamifier": "^0.1.1", "tar-stream": "^1.5.2" }, @@ -59,16 +60,16 @@ "url": "https://github.com/ipfs/js-ipfs-api" }, "devDependencies": { - "aegir": "^9.2.1", + "aegir": "^9.4.0", "chai": "^3.5.0", - "eslint-plugin-react": "^6.8.0", + "eslint-plugin-react": "^6.9.0", "gulp": "^3.9.1", - "hapi": "^16.0.3", - "interface-ipfs-core": "^0.23.1", - "ipfsd-ctl": "^0.17.0", - "pre-commit": "^1.2.0", - "socket.io": "^1.7.1", - "socket.io-client": "^1.7.1", + "hapi": "^16.1.0", + "interface-ipfs-core": "^0.23.5", + "ipfsd-ctl": "^0.18.2", + "pre-commit": "^1.2.2", + "socket.io": "^1.7.2", + "socket.io-client": "^1.7.2", "stream-equal": "^0.1.12" }, "pre-commit": [ diff --git a/test/bitswap.spec.js b/test/bitswap.spec.js new file mode 100644 index 000000000..41d7ffb7e --- /dev/null +++ b/test/bitswap.spec.js @@ -0,0 +1,86 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const FactoryClient = require('./ipfs-factory/client') + +describe('.bitswap', () => { + let ipfs + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + done() + }) + }) + + after((done) => { + fc.dismantle(done) + }) + + describe('Callback API', () => { + it('.wantlist', (done) => { + ipfs.bitswap.wantlist((err, res) => { + expect(err).to.not.exist + expect(res).to.have.to.be.eql({ + Keys: null + }) + done() + }) + }) + + it('.stat', (done) => { + ipfs.bitswap.stat((err, res) => { + expect(err).to.not.exist + expect(res).to.have.property('BlocksReceived') + expect(res).to.have.property('DupBlksReceived') + expect(res).to.have.property('DupDataReceived') + expect(res).to.have.property('Peers') + expect(res).to.have.property('ProvideBufLen') + expect(res).to.have.property('Wantlist') + + done() + }) + }) + + it('.unwant', (done) => { + const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + ipfs.bitswap.unwant(key, (err) => { + expect(err).to.not.exist + done() + }) + }) + }) + + describe('Promise API', () => { + it('.wantlist', () => { + return ipfs.bitswap.wantlist() + .then((res) => { + expect(res).to.have.to.be.eql({ + Keys: null + }) + }) + }) + + it('.stat', () => { + return ipfs.bitswap.stat() + .then((res) => { + expect(res).to.have.property('BlocksReceived') + expect(res).to.have.property('DupBlksReceived') + expect(res).to.have.property('DupDataReceived') + expect(res).to.have.property('Peers') + expect(res).to.have.property('ProvideBufLen') + expect(res).to.have.property('Wantlist') + }) + }) + + it('.unwant', () => { + const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + return ipfs.bitswap.unwant(key) + }) + }) +}) diff --git a/test/interface-ipfs-core/bootstrap.spec.js b/test/bootstrap.spec.js similarity index 56% rename from test/interface-ipfs-core/bootstrap.spec.js rename to test/bootstrap.spec.js index 4b04f92ac..168a6cd14 100644 --- a/test/interface-ipfs-core/bootstrap.spec.js +++ b/test/bootstrap.spec.js @@ -3,7 +3,7 @@ 'use strict' const expect = require('chai').expect -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('./ipfs-factory/client') const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' @@ -28,86 +28,88 @@ describe('.bootstrap', () => { let peers - describe('.add', () => { - it('returns an error when called with an invalid arg', (done) => { - ipfs.bootstrap.add(invalidArg, (err) => { - expect(err).to.be.an.instanceof(Error) - done() - }) - }) - - it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => { - ipfs.bootstrap.add(validIp4, (err, res) => { - expect(err).to.not.exist - expect(res).to.be.eql({ Peers: [validIp4] }) - peers = res.Peers - expect(peers).to.exist - expect(peers.length).to.eql(1) - done() - }) - }) - - it('returns a list of bootstrap peers when called with the default option', (done) => { - ipfs.bootstrap.add({ default: true }, (err, res) => { - expect(err).to.not.exist - peers = res.Peers - expect(peers).to.exist - expect(peers.length).to.above(1) - done() - }) - }) - }) - - describe('.list', () => { - it('returns a list of peers', (done) => { - ipfs.bootstrap.list((err, res) => { - expect(err).to.not.exist - peers = res.Peers - expect(peers).to.exist - done() - }) - }) - }) - - describe('.rm', () => { - it('returns an error when called with an invalid arg', (done) => { - ipfs.bootstrap.rm(invalidArg, (err) => { - expect(err).to.be.an.instanceof(Error) - done() - }) - }) - - it('returns empty list because no peers removed when called without an arg or options', (done) => { - ipfs.bootstrap.rm(null, (err, res) => { - expect(err).to.not.exist - peers = res.Peers - expect(peers).to.exist - expect(peers.length).to.eql(0) - done() + describe('Callback API', () => { + describe('.add', () => { + it('returns an error when called with an invalid arg', (done) => { + ipfs.bootstrap.add(invalidArg, (err) => { + expect(err).to.be.an.instanceof(Error) + done() + }) + }) + + it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => { + ipfs.bootstrap.add(validIp4, (err, res) => { + expect(err).to.not.exist + expect(res).to.be.eql({ Peers: [validIp4] }) + peers = res.Peers + expect(peers).to.exist + expect(peers.length).to.eql(1) + done() + }) + }) + + it('returns a list of bootstrap peers when called with the default option', (done) => { + ipfs.bootstrap.add({ default: true }, (err, res) => { + expect(err).to.not.exist + peers = res.Peers + expect(peers).to.exist + expect(peers.length).to.above(1) + done() + }) }) }) - it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { - ipfs.bootstrap.rm(null, (err, res) => { - expect(err).to.not.exist - peers = res.Peers - expect(peers).to.exist - expect(peers.length).to.eql(0) - done() + describe('.list', () => { + it('returns a list of peers', (done) => { + ipfs.bootstrap.list((err, res) => { + expect(err).to.not.exist + peers = res.Peers + expect(peers).to.exist + done() + }) }) }) - it('returns list of all peers removed when all option is passed', (done) => { - ipfs.bootstrap.rm(null, { all: true }, (err, res) => { - expect(err).to.not.exist - peers = res.Peers - expect(peers).to.exist - done() + describe('.rm', () => { + it('returns an error when called with an invalid arg', (done) => { + ipfs.bootstrap.rm(invalidArg, (err) => { + expect(err).to.be.an.instanceof(Error) + done() + }) + }) + + it('returns empty list because no peers removed when called without an arg or options', (done) => { + ipfs.bootstrap.rm(null, (err, res) => { + expect(err).to.not.exist + peers = res.Peers + expect(peers).to.exist + expect(peers.length).to.eql(0) + done() + }) + }) + + it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { + ipfs.bootstrap.rm(null, (err, res) => { + expect(err).to.not.exist + peers = res.Peers + expect(peers).to.exist + expect(peers.length).to.eql(0) + done() + }) + }) + + it('returns list of all peers removed when all option is passed', (done) => { + ipfs.bootstrap.rm(null, { all: true }, (err, res) => { + expect(err).to.not.exist + peers = res.Peers + expect(peers).to.exist + done() + }) }) }) }) - describe('.promise', () => { + describe('Promise API', () => { describe('.add', () => { it('returns an error when called without args or options', () => { return ipfs.bootstrap.add(null) diff --git a/test/browser.js b/test/browser.js deleted file mode 100644 index ebfd1aada..000000000 --- a/test/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' - -require('./setup/setup-ipfs-api-clients') diff --git a/test/interface-ipfs-core/commands.spec.js b/test/commands.spec.js similarity index 92% rename from test/interface-ipfs-core/commands.spec.js rename to test/commands.spec.js index e18b0ca24..b4ca05cd9 100644 --- a/test/interface-ipfs-core/commands.spec.js +++ b/test/commands.spec.js @@ -2,7 +2,7 @@ 'use strict' const expect = require('chai').expect -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('./ipfs-factory/client') describe('.commands', () => { let ipfs diff --git a/test/constructor.spec.js b/test/constructor.spec.js new file mode 100644 index 000000000..d46bc39f8 --- /dev/null +++ b/test/constructor.spec.js @@ -0,0 +1,61 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const FactoryClient = require('./ipfs-factory/client') + +const ipfsAPI = require('../src/index.js') + +function clientWorks (client, done) { + client.id((err, id) => { + expect(err).to.not.exist + + expect(id).to.have.a.property('id') + expect(id).to.have.a.property('publicKey') + done() + }) +} + +describe('ipfs-api constructor tests', () => { + describe('parameter permuations', () => { + let apiAddr + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + fc.spawnNode((err, node) => { + expect(err).to.not.exist + apiAddr = node.apiAddr + done() + }) + }) + + after((done) => fc.dismantle(done)) + + it('opts', (done) => { + const splitted = apiAddr.split('/') + clientWorks(ipfsAPI({ + host: splitted[2], + port: splitted[4], + protocol: 'http' + }), done) + }) + + it('mutliaddr, opts', (done) => { + clientWorks(ipfsAPI(apiAddr, { protocol: 'http' }), done) + }) + + it('host, port', (done) => { + const splitted = apiAddr.split('/') + + clientWorks(ipfsAPI(splitted[2], splitted[4]), done) + }) + + it('host, port, opts', (done) => { + const splitted = apiAddr.split('/') + + clientWorks(ipfsAPI(splitted[2], splitted[4], { protocol: 'http' }), done) + }) + }) +}) diff --git a/test/diag.spec.js b/test/diag.spec.js new file mode 100644 index 000000000..e0d2afd13 --- /dev/null +++ b/test/diag.spec.js @@ -0,0 +1,71 @@ +/* eslint-env mocha */ +'use strict' + +const FactoryClient = require('./ipfs-factory/client') +const expect = require('chai').expect + +describe('.diag', () => { + let ipfs + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + done() + }) + }) + + after((done) => fc.dismantle(done)) + + describe('Callback API', () => { + it('.diag.net', (done) => { + ipfs.diag.net((err, res) => { + expect(err).to.not.exist + expect(res).to.exist + done() + }) + }) + + it('.diag.sys', (done) => { + ipfs.diag.sys((err, res) => { + expect(err).to.not.exist + expect(res).to.exist + expect(res).to.have.a.property('memory') + expect(res).to.have.a.property('diskinfo') + done() + }) + }) + + it('.diag.cmds', (done) => { + ipfs.diag.cmds((err, res) => { + expect(err).to.not.exist + expect(res).to.exist + done() + }) + }) + }) + + describe('Promise API', () => { + it('.diag.net', () => { + return ipfs.diag.net() + .then((res) => expect(res).to.exist) + }) + + it('.diag.sys', () => { + return ipfs.diag.sys() + .then((res) => { + expect(res).to.exist + expect(res).to.have.a.property('memory') + expect(res).to.have.a.property('diskinfo') + }) + }) + + it('.diag.cmds', () => { + return ipfs.diag.cmds() + .then((res) => expect(res).to.exist) + }) + }) +}) diff --git a/test/files.spec.js b/test/files.spec.js new file mode 100644 index 000000000..c93073a0c --- /dev/null +++ b/test/files.spec.js @@ -0,0 +1,281 @@ +/* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 8] */ +'use strict' + +const expect = require('chai').expect +const isNode = require('detect-node') +const loadFixture = require('aegir/fixtures') + +const FactoryClient = require('./ipfs-factory/client') + +const testfile = isNode + ? loadFixture(__dirname, '/fixtures/testfile.txt') + : loadFixture(__dirname, 'fixtures/testfile.txt') + +describe('.files (the MFS API part)', () => { + let ipfs + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + done() + }) + }) + + after((done) => fc.dismantle(done)) + + describe('Callback API', () => { + it('add file for testing', (done) => { + const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + + ipfs.files.add(testfile, (err, res) => { + expect(err).to.not.exist + + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedMultihash) + expect(res[0].path).to.equal(expectedMultihash) + done() + }) + }) + + it('files.mkdir', (done) => { + ipfs.files.mkdir('/test-folder', done) + }) + + it('files.cp', (done) => { + ipfs.files.cp([ + '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + '/test-folder/test-file' + ], (err) => { + expect(err).to.not.exist + done() + }) + }) + + it('files.ls', (done) => { + ipfs.files.ls('/test-folder', (err, res) => { + expect(err).to.not.exist + expect(res.Entries.length).to.equal(1) + done() + }) + }) + + it('files.write', (done) => { + ipfs.files + .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}, (err) => { + expect(err).to.not.exist + + ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { + expect(err).to.not.exist + + let buf = '' + stream + .on('error', (err) => expect(err).to.not.exist) + .on('data', (data) => { + buf += data + }) + .on('end', () => { + expect(buf).to.be.equal('hello world') + done() + }) + }) + }) + }) + + it('files.write without options', (done) => { + ipfs.files + .write('/test-folder/test-file-2.txt', new Buffer('hello world'), (err) => { + expect(err).to.not.exist + + ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { + expect(err).to.not.exist + + let buf = '' + stream + .on('error', (err) => { + expect(err).to.not.exist + }) + .on('data', (data) => { + buf += data + }) + .on('end', () => { + expect(buf).to.be.equal('hello world') + done() + }) + }) + }) + }) + + it('files.stat', (done) => { + ipfs.files.stat('/test-folder/test-file', (err, res) => { + expect(err).to.not.exist + expect(res).to.deep.equal({ + Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + Size: 12, + CumulativeSize: 20, + Blocks: 0, + Type: 'file' + }) + + done() + }) + }) + + it('files.stat file that does not exist', (done) => { + ipfs.files.stat('/test-folder/does-not-exist', (err, res) => { + expect(err).to.exist + if (err.code === 0) { + return done() + } + throw err + }) + }) + + it('files.read', (done) => { + if (!isNode) { + return done() + } + + ipfs.files.read('/test-folder/test-file', (err, stream) => { + expect(err).to.not.exist + let buf = '' + stream + .on('error', (err) => { + expect(err).to.not.exist + }) + .on('data', (data) => { + buf += data + }) + .on('end', () => { + expect(new Buffer(buf)).to.deep.equal(testfile) + done() + }) + }) + }) + + it('files.rm without options', (done) => { + ipfs.files.rm('/test-folder/test-file-2.txt', done) + }) + + it('files.rm', (done) => { + ipfs.files.rm('/test-folder', {recursive: true}, done) + }) + }) + + describe('Promise API', () => { + it('files.mkdir', () => { + return ipfs.files.mkdir('/test-folder') + }) + + it('files.cp', () => { + return ipfs.files + .cp(['/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file']) + }) + + it('files.ls', () => { + return ipfs.files.ls('/test-folder') + .then((res) => { + expect(res.Entries.length).to.equal(1) + }) + }) + + it('files.write', (done) => { + ipfs.files + .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}) + .then(() => { + return ipfs.files.read('/test-folder/test-file-2.txt') + }) + .then((stream) => { + let buf = '' + stream + .on('error', (err) => { + expect(err).to.not.exist + }) + .on('data', (data) => { + buf += data + }) + .on('end', () => { + expect(buf).to.be.equal('hello world') + done() + }) + }) + .catch(done) + }) + + it('files.write without options', (done) => { + ipfs.files + .write('/test-folder/test-file-2.txt', new Buffer('hello world')) + .then(() => { + return ipfs.files.read('/test-folder/test-file-2.txt') + }) + .then((stream) => { + let buf = '' + stream + .on('error', (err) => { + expect(err).to.not.exist + }) + .on('data', (data) => { + buf += data + }) + .on('end', () => { + expect(buf).to.be.equal('hello world') + done() + }) + }) + .catch(done) + }) + + it('files.stat', () => { + return ipfs.files.stat('/test-folder/test-file') + .then((res) => { + expect(res).to.deep.equal({ + Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', + Size: 12, + CumulativeSize: 20, + Blocks: 0, + Type: 'file' + }) + }) + }) + + it('files.stat file that does not exist', () => { + return ipfs.files.stat('/test-folder/does-not-exist') + .catch((err) => { + expect(err).to.exist + expect(err.code).to.be.eql(0) + }) + }) + + it('files.read', (done) => { + if (!isNode) { return done() } + + ipfs.files.read('/test-folder/test-file') + .then((stream) => { + let buf = '' + stream + .on('error', (err) => { + expect(err).to.not.exist + }) + .on('data', (data) => { + buf += data + }) + .on('end', () => { + expect(new Buffer(buf)).to.deep.equal(testfile) + done() + }) + }) + }) + + it('files.rm without options', () => { + return ipfs.files.rm('/test-folder/test-file-2.txt') + }) + + it('files.rm', () => { + return ipfs.files.rm('/test-folder', { recursive: true }) + }) + }) +}) diff --git a/test/interface-ipfs-core/get.spec.js b/test/get.spec.js similarity index 52% rename from test/interface-ipfs-core/get.spec.js rename to test/get.spec.js index fe6d22505..f0a009479 100644 --- a/test/interface-ipfs-core/get.spec.js +++ b/test/get.spec.js @@ -11,15 +11,15 @@ const through = require('through2') const streamEqual = require('stream-equal') const path = require('path') const loadFixture = require('aegir/fixtures') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('./ipfs-factory/client') let testfile let testfileBig let tfbPath if (isNode) { - tfbPath = path.join(__dirname, '../fixtures/15mb.random') + tfbPath = path.join(__dirname, '/fixtures/15mb.random') testfileBig = fs.createReadStream(tfbPath, { bufferSize: 128 }) - testfile = loadFixture(__dirname, '../fixtures/testfile.txt') + testfile = loadFixture(__dirname, '/fixtures/testfile.txt') } else { testfile = loadFixture(__dirname, 'fixtures/testfile.txt') } @@ -38,30 +38,29 @@ describe('.get', () => { }) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => fc.dismantle(done)) - it('add file for testing', (done) => { - const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + describe('Callback API', () => { + it('add file for testing', (done) => { + const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - ipfs.files.add(testfile, (err, res) => { - expect(err).to.not.exist + ipfs.files.add(testfile, (err, res) => { + expect(err).to.not.exist - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedMultihash) - expect(res[0].path).to.equal(expectedMultihash) - done() + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedMultihash) + expect(res[0].path).to.equal(expectedMultihash) + done() + }) }) - }) - it('get with no compression args', (done) => { - ipfs - .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { + it('get with no compression args', (done) => { + ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { expect(err).to.not.exist // accumulate the files and their content var files = [] + res.pipe(through.obj((file, enc, next) => { file.content.pipe(concat((content) => { files.push({ @@ -76,15 +75,17 @@ describe('.get', () => { done() })) }) - }) + }) - it('get with archive true', (done) => { - ipfs - .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {archive: true}, (err, res) => { + it('get with archive true', (done) => { + ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', { + archive: true + }, (err, res) => { expect(err).to.not.exist // accumulate the files and their content var files = [] + res.pipe(through.obj((file, enc, next) => { file.content.pipe(concat((content) => { files.push({ @@ -99,72 +100,71 @@ describe('.get', () => { done() })) }) - }) + }) - it('get err with out of range compression level', (done) => { - ipfs - .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {compress: true, 'compression-level': 10}, (err, res) => { + it('get err with out of range compression level', (done) => { + ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', { + compress: true, + 'compression-level': 10 + }, (err, res) => { expect(err).to.exist expect(err.toString()).to.equal('Error: Compression level must be between 1 and 9') done() }) - }) + }) - it('get with compression level', (done) => { - ipfs - .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {compress: true, 'compression-level': 1}, (err, res) => { + it('get with compression level', (done) => { + ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', { + compress: true, + 'compression-level': 1 + }, (err, res) => { expect(err).to.not.exist done() }) - }) + }) - it('add a BIG file (for testing get)', (done) => { - if (!isNode) { - return done() - } + it('add a BIG file (for testing get)', (done) => { + if (!isNode) { return done() } - const bigFile = fs.readFileSync(tfbPath) - const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' + const bigFile = fs.readFileSync(tfbPath) + const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' - ipfs.files.add(bigFile, (err, res) => { - expect(err).to.not.exist + ipfs.files.add(bigFile, (err, res) => { + expect(err).to.not.exist - expect(res).to.have.length(1) - expect(res[0].path).to.equal(expectedMultihash) - expect(res[0].hash).to.equal(expectedMultihash) - done() + expect(res).to.have.length(1) + expect(res[0].path).to.equal(expectedMultihash) + expect(res[0].hash).to.equal(expectedMultihash) + done() + }) }) - }) - it('get BIG file', (done) => { - if (!isNode) { - return done() - } + it('get BIG file', (done) => { + if (!isNode) { return done() } - ipfs.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, files) => { - expect(err).to.not.exist + ipfs.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, files) => { + expect(err).to.not.exist - files.on('data', (file) => { - // Do not blow out the memory of nodejs :) - streamEqual(file.content, testfileBig, (err, equal) => { - expect(err).to.not.exist - expect(equal).to.be.true - done() + files.on('data', (file) => { + // Do not blow out the memory of nodejs :) + streamEqual(file.content, testfileBig, (err, equal) => { + expect(err).to.not.exist + expect(equal).to.be.true + done() + }) }) }) }) }) - describe('promise', () => { + describe('Promise API', () => { it('get', (done) => { ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') .then((files) => { files.on('data', (file) => { let buf = '' file.content - .on('error', (err) => { - throw err - }) + .on('error', (err) => expect(err).to.not.exist) .on('data', (data) => { buf += data.toString() }) diff --git a/test/interface-ipfs-core/bitswap.spec.js b/test/interface-ipfs-core/bitswap.spec.js deleted file mode 100644 index d3a8d4b81..000000000 --- a/test/interface-ipfs-core/bitswap.spec.js +++ /dev/null @@ -1,67 +0,0 @@ -/* eslint-env mocha */ -/* globals apiClients */ -'use strict' - -const expect = require('chai').expect - -describe('.bitswap', () => { - it('.wantlist', (done) => { - apiClients.a.bitswap.wantlist((err, res) => { - expect(err).to.not.exist - expect(res).to.have.to.be.eql({ - Keys: null - }) - done() - }) - }) - - it('.stat', (done) => { - apiClients.a.bitswap.stat((err, res) => { - expect(err).to.not.exist - expect(res).to.have.property('BlocksReceived') - expect(res).to.have.property('DupBlksReceived') - expect(res).to.have.property('DupDataReceived') - expect(res).to.have.property('Peers') - expect(res).to.have.property('ProvideBufLen') - expect(res).to.have.property('Wantlist') - - done() - }) - }) - - it('.unwant', (done) => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - apiClients.a.bitswap.unwant(key, (err) => { - expect(err).to.not.exist - done() - }) - }) - - describe('promise', () => { - it('.wantlist', () => { - return apiClients.a.bitswap.wantlist() - .then((res) => { - expect(res).to.have.to.be.eql({ - Keys: null - }) - }) - }) - - it('.stat', () => { - return apiClients.a.bitswap.stat() - .then((res) => { - expect(res).to.have.property('BlocksReceived') - expect(res).to.have.property('DupBlksReceived') - expect(res).to.have.property('DupDataReceived') - expect(res).to.have.property('Peers') - expect(res).to.have.property('ProvideBufLen') - expect(res).to.have.property('Wantlist') - }) - }) - - it('.unwant', () => { - const key = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - return apiClients.a.bitswap.unwant(key) - }) - }) -}) diff --git a/test/interface-ipfs-core/diag.spec.js b/test/interface-ipfs-core/diag.spec.js deleted file mode 100644 index 198248343..000000000 --- a/test/interface-ipfs-core/diag.spec.js +++ /dev/null @@ -1,75 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const FactoryClient = require('../factory/factory-client') -const expect = require('chai').expect - -describe('.diag', () => { - let ipfs - let fc - - before(function (done) { - this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { - expect(err).to.not.exist - ipfs = node - done() - }) - }) - - after((done) => { - fc.dismantle(done) - }) - - it('.diag.net', (done) => { - ipfs.diag.net((err, res) => { - expect(err).to.not.exist - expect(res).to.exist - done() - }) - }) - - it('.diag.sys', (done) => { - ipfs.diag.sys((err, res) => { - expect(err).to.not.exist - expect(res).to.exist - expect(res).to.have.a.property('memory') - expect(res).to.have.a.property('diskinfo') - done() - }) - }) - - it('.diag.cmds', (done) => { - ipfs.diag.cmds((err, res) => { - expect(err).to.not.exist - expect(res).to.exist - done() - }) - }) - - describe('promise', () => { - it('.diag.net', () => { - return ipfs.diag.net() - .then((res) => { - expect(res).to.exist - }) - }) - - it('.diag.sys', () => { - return ipfs.diag.sys() - .then((res) => { - expect(res).to.exist - expect(res).to.have.a.property('memory') - expect(res).to.have.a.property('diskinfo') - }) - }) - - it('.diag.cmds', () => { - return ipfs.diag.cmds() - .then((res) => { - expect(res).to.exist - }) - }) - }) -}) diff --git a/test/interface-ipfs-core/files.spec.js b/test/interface-ipfs-core/files.spec.js deleted file mode 100644 index 43e181ce7..000000000 --- a/test/interface-ipfs-core/files.spec.js +++ /dev/null @@ -1,312 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const expect = require('chai').expect -const isNode = require('detect-node') -const test = require('interface-ipfs-core') -const loadFixture = require('aegir/fixtures') - -const FactoryClient = require('../factory/factory-client') - -let testfile -if (isNode) { - testfile = loadFixture(__dirname, '../fixtures/testfile.txt') -} else { - testfile = loadFixture(__dirname, 'fixtures/testfile.txt') -} - -// add, cat, get and ls tests from interface-ipfs-core -let fc - -const common = { - setup: function (callback) { - fc = new FactoryClient() - callback(null, fc) - }, - teardown: function (callback) { - fc.dismantle(callback) - } -} - -test.files(common) - -// mfs tests -describe('.files (pseudo mfs)', () => { - let ipfs - let fc - - before(function (done) { - this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { - expect(err).to.not.exist - ipfs = node - done() - }) - }) - - after((done) => { - fc.dismantle(done) - }) - - it('add file for testing', (done) => { - const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - - ipfs.files.add(testfile, (err, res) => { - expect(err).to.not.exist - - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedMultihash) - expect(res[0].path).to.equal(expectedMultihash) - done() - }) - }) - - it('files.mkdir', (done) => { - ipfs.files.mkdir('/test-folder', function (err) { - expect(err).to.not.exist - done() - }) - }) - - it('files.cp', (done) => { - ipfs.files - .cp(['/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file'], (err) => { - expect(err).to.not.exist - done() - }) - }) - - it('files.ls', (done) => { - ipfs.files.ls('/test-folder', (err, res) => { - expect(err).to.not.exist - expect(res.Entries.length).to.equal(1) - done() - }) - }) - - it('files.write', (done) => { - ipfs.files - .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}, (err) => { - expect(err).to.not.exist - - ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { - expect(err).to.not.exist - - let buf = '' - stream - .on('error', (err) => { - expect(err).to.not.exist - }) - .on('data', (data) => { - buf += data - }) - .on('end', () => { - expect(buf).to.be.equal('hello world') - done() - }) - }) - }) - }) - - it('files.write without options', (done) => { - ipfs.files - .write('/test-folder/test-file-2.txt', new Buffer('hello world'), (err) => { - expect(err).to.not.exist - - ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { - expect(err).to.not.exist - - let buf = '' - stream - .on('error', (err) => { - expect(err).to.not.exist - }) - .on('data', (data) => { - buf += data - }) - .on('end', () => { - expect(buf).to.be.equal('hello world') - done() - }) - }) - }) - }) - - it('files.stat', (done) => { - ipfs.files.stat('/test-folder/test-file', (err, res) => { - expect(err).to.not.exist - expect(res).to.deep.equal({ - Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - Size: 12, - CumulativeSize: 20, - Blocks: 0, - Type: 'file' - }) - - done() - }) - }) - - it('files.stat file that does not exist', (done) => { - ipfs.files.stat('/test-folder/does-not-exist', (err, res) => { - expect(err).to.exist - if (err.code === 0) { - return done() - } - throw err - }) - }) - - it('files.read', (done) => { - if (!isNode) { - return done() - } - - ipfs.files.read('/test-folder/test-file', (err, stream) => { - expect(err).to.not.exist - let buf = '' - stream - .on('error', (err) => { - expect(err).to.not.exist - }) - .on('data', (data) => { - buf += data - }) - .on('end', () => { - expect(new Buffer(buf)).to.deep.equal(testfile) - done() - }) - }) - }) - - it('files.rm without options', (done) => { - ipfs.files.rm('/test-folder/test-file-2.txt', (err) => { - expect(err).to.not.exist - done() - }) - }) - - it('files.rm', (done) => { - ipfs.files.rm('/test-folder', {recursive: true}, (err) => { - expect(err).to.not.exist - done() - }) - }) - - describe('promise', () => { - it('files.mkdir', () => { - return ipfs.files.mkdir('/test-folder') - }) - - it('files.cp', () => { - return ipfs.files - .cp(['/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file']) - }) - - it('files.ls', () => { - return ipfs.files.ls('/test-folder') - .then((res) => { - expect(res.Entries.length).to.equal(1) - }) - }) - - it('files.write', (done) => { - ipfs.files - .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}) - .then(() => { - return ipfs.files.read('/test-folder/test-file-2.txt') - }) - .then((stream) => { - let buf = '' - stream - .on('error', (err) => { - expect(err).to.not.exist - }) - .on('data', (data) => { - buf += data - }) - .on('end', () => { - expect(buf).to.be.equal('hello world') - done() - }) - }) - .catch(done) - }) - - it('files.write without options', (done) => { - ipfs.files - .write('/test-folder/test-file-2.txt', new Buffer('hello world')) - .then(() => { - return ipfs.files.read('/test-folder/test-file-2.txt') - }) - .then((stream) => { - let buf = '' - stream - .on('error', (err) => { - expect(err).to.not.exist - }) - .on('data', (data) => { - buf += data - }) - .on('end', () => { - expect(buf).to.be.equal('hello world') - done() - }) - }) - .catch(done) - }) - - it('files.stat', () => { - return ipfs.files.stat('/test-folder/test-file') - .then((res) => { - expect(res).to.deep.equal({ - Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', - Size: 12, - CumulativeSize: 20, - Blocks: 0, - Type: 'file' - }) - }) - }) - - it('files.stat file that does not exist', () => { - return ipfs.files.stat('/test-folder/does-not-exist') - .catch((err) => { - expect(err).to.exist - expect(err.code).to.be.eql(0) - }) - }) - - it('files.read', (done) => { - if (!isNode) { - return done() - } - - ipfs.files.read('/test-folder/test-file') - .then((stream) => { - let buf = '' - stream - .on('error', (err) => { - expect(err).to.not.exist - }) - .on('data', (data) => { - buf += data - }) - .on('end', () => { - expect(new Buffer(buf)).to.deep.equal(testfile) - done() - }) - }) - }) - - it('files.rm without options', () => { - return ipfs.files.rm('/test-folder/test-file-2.txt') - }) - - it('files.rm', () => { - return ipfs.files.rm('/test-folder', {recursive: true}) - }) - }) -}) diff --git a/test/interface-ipfs-core/log.spec.js b/test/interface-ipfs-core/log.spec.js deleted file mode 100644 index 11710b780..000000000 --- a/test/interface-ipfs-core/log.spec.js +++ /dev/null @@ -1,54 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const expect = require('chai').expect -const isNode = require('detect-node') -const FactoryClient = require('../factory/factory-client') - -// For some reason these tests time out in PhantomJS so we need to skip them -const isPhantom = !isNode && typeof navigator !== 'undefined' && navigator.userAgent.match(/PhantomJS/) - -if (!isPhantom) { - describe('.log', () => { - let ipfs - let fc - - before(function (done) { - this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { - expect(err).to.not.exist - ipfs = node - done() - }) - }) - - after((done) => { - fc.dismantle(done) - }) - - it('.log.tail', (done) => { - const req = ipfs.log.tail((err, res) => { - expect(err).to.not.exist - expect(req).to.exist - - res.once('data', (obj) => { - expect(obj).to.be.an('object') - done() - }) - }) - }) - - describe('promise', () => { - it('.log.tail', () => { - return ipfs.log.tail() - .then((res) => { - res.once('data', (obj) => { - expect(obj).to.be.an('object') - }) - }) - }) - }) - }) -} diff --git a/test/interface-ipfs-core/mount.spec.js b/test/interface-ipfs-core/mount.spec.js deleted file mode 100644 index 9f100d1f5..000000000 --- a/test/interface-ipfs-core/mount.spec.js +++ /dev/null @@ -1,6 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -describe('.mount', () => { - // requires FUSE to be installed, not practical for testing -}) diff --git a/test/interface-ipfs-core/name.spec.js b/test/interface-ipfs-core/name.spec.js deleted file mode 100644 index 20de8f012..000000000 --- a/test/interface-ipfs-core/name.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -/* eslint-env mocha */ -/* globals apiClients */ -'use strict' - -const expect = require('chai').expect -const isNode = require('detect-node') -const loadFixture = require('aegir/fixtures') - -let testfile -if (isNode) { - testfile = loadFixture(__dirname, '../fixtures/testfile.txt') -} else { - testfile = loadFixture(__dirname, 'fixtures/testfile.txt') -} - -describe('.name', () => { - let name - - it('add file for testing', (done) => { - const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' - - apiClients.a.files.add(testfile, (err, res) => { - expect(err).to.not.exist - - expect(res).to.have.length(1) - expect(res[0].hash).to.equal(expectedMultihash) - expect(res[0].path).to.equal(expectedMultihash) - done() - }) - }) - - it('.name.publish', (done) => { - apiClients.a.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { - expect(err).to.not.exist - name = res - expect(name).to.exist - done() - }) - }) - - it('.name.resolve', (done) => { - apiClients.a.name.resolve(name.Name, (err, res) => { - expect(err).to.not.exist - expect(res).to.exist - expect(res).to.be.eql({ - Path: '/ipfs/' + name.Value - }) - done() - }) - }) - - describe('promise', () => { - it('.name.publish', () => { - return apiClients.a.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') - .then((res) => { - name = res - expect(name).to.exist - }) - }) - - it('.name.resolve', () => { - return apiClients.a.name.resolve(name.Name) - .then((res) => { - expect(res).to.exist - expect(res).to.be.eql({ - Path: '/ipfs/' + name.Value - }) - }) - }) - }) -}) diff --git a/test/interface-ipfs-core/ping.spec.js b/test/interface-ipfs-core/ping.spec.js deleted file mode 100644 index a7dbb4a28..000000000 --- a/test/interface-ipfs-core/ping.spec.js +++ /dev/null @@ -1,39 +0,0 @@ -/* eslint-env mocha */ -/* globals apiClients */ -'use strict' - -const expect = require('chai').expect - -describe('.ping', () => { - it('ping another peer', (done) => { - apiClients.b.id((err, id) => { - expect(err).to.not.exist - - apiClients.a.ping(id.id, (err, res) => { - expect(err).to.not.exist - expect(res).to.have.a.property('Success') - expect(res).to.have.a.property('Time') - expect(res).to.have.a.property('Text') - expect(res.Text).to.contain('Average latency') - expect(res.Time).to.be.a('number') - done() - }) - }) - }) - - describe('promise', () => { - it('ping another peer', () => { - return apiClients.b.id() - .then((id) => { - return apiClients.a.ping(id.id) - }) - .then((res) => { - expect(res).to.have.a.property('Success') - expect(res).to.have.a.property('Time') - expect(res).to.have.a.property('Text') - expect(res.Text).to.contain('Average latency') - expect(res.Time).to.be.a('number') - }) - }) - }) -}) diff --git a/test/interface-ipfs-core/refs.spec.js b/test/interface-ipfs-core/refs.spec.js deleted file mode 100644 index 3a38abe1f..000000000 --- a/test/interface-ipfs-core/refs.spec.js +++ /dev/null @@ -1,80 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const expect = require('chai').expect -const isNode = require('detect-node') -const waterfall = require('async/waterfall') -const path = require('path') -const FactoryClient = require('../factory/factory-client') - -describe('.refs', () => { - if (!isNode) { - return - } - - let ipfs - let fc - let folder - - before(function (done) { - this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - waterfall([ - (cb) => fc.spawnNode(cb), - (node, cb) => { - ipfs = node - const filesPath = path.join(__dirname, '../fixtures/test-folder') - ipfs.util.addFromFs(filesPath, { recursive: true }, cb) - }, - (hashes, cb) => { - folder = hashes[hashes.length - 1].hash - expect(folder).to.be.eql('QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh') - cb() - } - ], done) - }) - - after((done) => { - fc.dismantle(done) - }) - - const result = [{ - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmcUYKmQxmTcFom4R4UZP7FWeQzgJkwcFn51XrvsMy7PE9 add', - Err: '' - }, { - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmNeHxDfQfjVFyYj2iruvysLH9zpp78v3cu1s3BZq1j5hY cat', - Err: '' - }, { - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmTYFLz5vsdMpq4XXw1a1pSxujJc9Z5V3Aw1Qg64d849Zy files', - Err: '' - }, { - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu hello-link', - Err: '' - }, { - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmU7wetVaAqc3Meurif9hcYBHGvQmL5QdpPJYBoZizyTNL ipfs-add', - Err: '' - }, { - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmctZfSuegbi2TMFY2y3VQjxsH5JbRBu7XmiLfHNvshhio ls', - Err: '' - }, { - Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmbkMNB6rwfYAxRvnG9CWJ6cKKHEdq2ZKTozyF5FQ7H8Rs version', - Err: '' - }] - - it('refs', (done) => { - ipfs.refs(folder, {format: ' '}, (err, objs) => { - expect(err).to.not.exist - expect(objs).to.eql(result) - done() - }) - }) - - describe('promise', () => { - it('refs', () => { - return ipfs.refs(folder, {format: ' '}) - .then((objs) => { - expect(objs).to.eql(result) - }) - }) - }) -}) diff --git a/test/interface/block.spec.js b/test/interface/block.spec.js new file mode 100644 index 000000000..ce96664dc --- /dev/null +++ b/test/interface/block.spec.js @@ -0,0 +1,20 @@ +/* eslint-env mocha */ + +'use strict' + +const test = require('interface-ipfs-core') +const Factory = require('../ipfs-factory/client') + +let factory + +const common = { + setup: function (callback) { + factory = new Factory() + callback(null, factory) + }, + teardown: function (callback) { + factory.dismantle(callback) + } +} + +test.block(common) diff --git a/test/interface-ipfs-core/config.spec.js b/test/interface/config.spec.js similarity index 84% rename from test/interface-ipfs-core/config.spec.js rename to test/interface/config.spec.js index 794fd4678..0527c954e 100644 --- a/test/interface-ipfs-core/config.spec.js +++ b/test/interface/config.spec.js @@ -3,7 +3,7 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('../ipfs-factory/client') let fc diff --git a/test/interface-ipfs-core/dht.spec.js b/test/interface/dht.spec.js similarity index 82% rename from test/interface-ipfs-core/dht.spec.js rename to test/interface/dht.spec.js index ed6c9a162..b1e731e77 100644 --- a/test/interface-ipfs-core/dht.spec.js +++ b/test/interface/dht.spec.js @@ -2,7 +2,7 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('../ipfs-factory/client') let fc diff --git a/test/interface-ipfs-core/block.spec.js b/test/interface/files.spec.js similarity index 68% rename from test/interface-ipfs-core/block.spec.js rename to test/interface/files.spec.js index 2254715a2..8170ce597 100644 --- a/test/interface-ipfs-core/block.spec.js +++ b/test/interface/files.spec.js @@ -1,9 +1,10 @@ /* eslint-env mocha */ - +/* eslint max-nested-callbacks: ["error", 8] */ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') + +const FactoryClient = require('../ipfs-factory/client') let fc @@ -17,4 +18,4 @@ const common = { } } -test.block(common) +test.files(common) diff --git a/test/interface-ipfs-core/generic.spec.js b/test/interface/generic.spec.js similarity index 82% rename from test/interface-ipfs-core/generic.spec.js rename to test/interface/generic.spec.js index 6731ad9bb..2e4403c60 100644 --- a/test/interface-ipfs-core/generic.spec.js +++ b/test/interface/generic.spec.js @@ -3,7 +3,7 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('../ipfs-factory/client') let fc diff --git a/test/interface-ipfs-core/object.spec.js b/test/interface/object.spec.js similarity index 82% rename from test/interface-ipfs-core/object.spec.js rename to test/interface/object.spec.js index 9375bf087..ea127d09c 100644 --- a/test/interface-ipfs-core/object.spec.js +++ b/test/interface/object.spec.js @@ -3,7 +3,7 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('../ipfs-factory/client') let fc diff --git a/test/interface-ipfs-core/swarm.spec.js b/test/interface/swarm.spec.js similarity index 84% rename from test/interface-ipfs-core/swarm.spec.js rename to test/interface/swarm.spec.js index c01610d08..420f08543 100644 --- a/test/interface-ipfs-core/swarm.spec.js +++ b/test/interface/swarm.spec.js @@ -3,7 +3,7 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('../ipfs-factory/client') let fc diff --git a/test/ipfs-api/constructor.spec.js b/test/ipfs-api/constructor.spec.js deleted file mode 100644 index f134af061..000000000 --- a/test/ipfs-api/constructor.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const expect = require('chai').expect - -const ipfsAPI = require('./../../src/index.js') - -describe('ipfsAPI constructor tests', () => { - describe('parameter permuations', () => { - const apiAddrs = require('./../setup/tmp-disposable-nodes-addrs.json') - const apiAddr = apiAddrs.a.split('/') - - function clientWorks (client, done) { - client.id((err, id) => { - expect(err).to.not.exist - - expect(id).to.have.a.property('id') - expect(id).to.have.a.property('publicKey') - done() - }) - } - - it('opts', (done) => { - clientWorks(ipfsAPI({ - host: apiAddr[2], - port: apiAddr[4], - protocol: 'http' - }), done) - }) - - it('mutliaddr, opts', (done) => { - clientWorks(ipfsAPI( - apiAddrs.a, - {protocol: 'http'} - ), done) - }) - - it('host, port', (done) => { - clientWorks(ipfsAPI( - apiAddr[2], - apiAddr[4] - ), done) - }) - - it('host, port, opts', (done) => { - clientWorks(ipfsAPI( - apiAddr[2], - apiAddr[4], - {protocol: 'http'} - ), done) - }) - }) -}) diff --git a/test/ipfs-api/util.spec.js b/test/ipfs-api/util.spec.js deleted file mode 100644 index 374142266..000000000 --- a/test/ipfs-api/util.spec.js +++ /dev/null @@ -1,110 +0,0 @@ -/* eslint-env mocha */ -/* eslint max-nested-callbacks: ["error", 8] */ -'use strict' - -const expect = require('chai').expect -const isNode = require('detect-node') -const path = require('path') -const fs = require('fs') -const FactoryClient = require('../factory/factory-client') - -describe('.util', () => { - if (!isNode) { - return - } - - let ipfs - let fc - - before(function (done) { - this.timeout(20 * 1000) // slow CI - fc = new FactoryClient() - fc.spawnNode((err, node) => { - expect(err).to.not.exist - ipfs = node - done() - }) - }) - - after((done) => { - fc.dismantle(done) - }) - - it('.streamAdd', (done) => { - const tfpath = path.join(__dirname, '/../fixtures/testfile.txt') - const rs = fs.createReadStream(tfpath) - rs.path = '' // clean the path for testing purposes - - ipfs.util.addFromStream(rs, (err, result) => { - expect(err).to.not.exist - expect(result.length).to.equal(1) - done() - }) - }) - - describe('.fsAdd should add', () => { - it('a directory', (done) => { - const filesPath = path.join(__dirname, '../fixtures/test-folder') - ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => { - expect(err).to.not.exist - expect(result.length).to.be.above(8) - done() - }) - }) - - it('a directory with an odd name', (done) => { - const filesPath = path.join(__dirname, '../fixtures/weird name folder [v0]') - ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => { - expect(err).to.not.exist - expect(result.length).to.be.above(8) - done() - }) - }) - - it('add and ignore a directory', (done) => { - const filesPath = path.join(__dirname, '../fixtures/test-folder') - ipfs.util.addFromFs(filesPath, { recursive: true, ignore: ['files/**'] }, (err, result) => { - expect(err).to.not.exist - expect(result.length).to.be.below(9) - done() - }) - }) - - it('a file', (done) => { - const filePath = path.join(__dirname, '../fixtures/testfile.txt') - ipfs.util.addFromFs(filePath, (err, result) => { - expect(err).to.not.exist - expect(result.length).to.be.equal(1) - expect(result[0].path).to.be.equal('testfile.txt') - done() - }) - }) - - it('a hidden file in a directory', (done) => { - const filesPath = path.join(__dirname, '../fixtures/test-folder') - ipfs.util.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { - expect(err).to.not.exist - expect(result.length).to.be.above(10) - expect(result.map(object => object.path)).to.include('test-folder/.hiddenTest.txt') - expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') - done() - }) - }) - }) - - it('.urlAdd http', (done) => { - ipfs.util.addFromURL('http://example.com/', (err, result) => { - expect(err).to.not.exist - expect(result.length).to.equal(1) - done() - }) - }) - - it('.urlAdd https', (done) => { - ipfs.util.addFromURL('https://example.com/', (err, result) => { - expect(err).to.not.exist - expect(result.length).to.equal(1) - done() - }) - }) -}) diff --git a/test/factory/factory-client.js b/test/ipfs-factory/client.js similarity index 97% rename from test/factory/factory-client.js rename to test/ipfs-factory/client.js index 31fde6ac0..5d2685b5c 100644 --- a/test/factory/factory-client.js +++ b/test/ipfs-factory/client.js @@ -41,6 +41,7 @@ function Factory () { function spawnNode () { ioC.once('fc-node', (apiAddr) => { const ipfs = ipfsAPI(apiAddr) + ipfs.apiAddr = apiAddr callback(null, ipfs) }) ioC.emit('fs-spawn-node', repoPath, config) diff --git a/test/factory/daemon-spawner.js b/test/ipfs-factory/daemon-spawner.js similarity index 62% rename from test/factory/daemon-spawner.js rename to test/ipfs-factory/daemon-spawner.js index 86a2d808b..6526555c6 100644 --- a/test/factory/daemon-spawner.js +++ b/test/ipfs-factory/daemon-spawner.js @@ -1,6 +1,5 @@ 'use strict' -// const defaultConfig = require('./default-config.json') const ipfsd = require('ipfsd-ctl') const series = require('async/series') const eachSeries = require('async/eachSeries') @@ -25,23 +24,17 @@ function Factory () { config = undefined } - // if (!repoPath) { - // repoPath = '/tmp/.ipfs-' + Math.random() - // .toString() - // .substring(2, 8) - // } - // TODO - // - [ ] Support custom repoPath - // - [ ] Support custom config - // This will come once the new ipfsd-ctl is - // complete: https://github.com/ipfs/js-ipfsd-ctl/pull/89 + // support custom repoPath + // support custom configs being passed spawnEphemeralNode((err, node) => { if (err) { return callback(err) } + nodes.push(node) + callback(null, node.apiAddr) }) } @@ -54,6 +47,7 @@ function Factory () { if (err) { return callback(err) } + nodes = [] callback() @@ -66,30 +60,31 @@ function spawnEphemeralNode (callback) { if (err) { return callback(err) } + // Note: we have to set each config value // independently since the config/replace endpoint // doesn't work as expected series([ (cb) => { const configValues = { - Bootstrap: [], - Discovery: {}, - 'HTTPHeaders.Access-Control-Allow-Origin': ['*'], - 'HTTPHeaders.Access-Control-Allow-Credentials': 'true', - 'HTTPHeaders.Access-Control-Allow-Methods': ['PUT', 'POST', 'GET'] + 'Bootstrap': [], + 'Discovery': {}, + 'API.HTTPHeaders.Access-Control-Allow-Origin': ['*'], + // This is not needed after all + // 'API.HTTPHeaders.Access-Control-Allow-Credentials': true, + 'API.HTTPHeaders.Access-Control-Allow-Methods': [ + 'PUT', + 'POST', + 'GET' + ] } eachSeries(Object.keys(configValues), (configKey, cb) => { - node.setConfig(`API.${configKey}`, JSON.stringify(configValues[configKey]), cb) + const configVal = JSON.stringify(configValues[configKey]) + node.setConfig(configKey, configVal, cb) }, cb) }, (cb) => node.startDaemon(cb) - ], (err) => { - if (err) { - return callback(err) - } - - callback(null, node) - }) + ], (err) => callback(err, node)) }) } diff --git a/test/factory/factory-server-routes.js b/test/ipfs-factory/server-routes.js similarity index 100% rename from test/factory/factory-server-routes.js rename to test/ipfs-factory/server-routes.js diff --git a/test/factory/factory-server.js b/test/ipfs-factory/server.js similarity index 90% rename from test/factory/factory-server.js rename to test/ipfs-factory/server.js index 6482714f2..9f4663334 100644 --- a/test/factory/factory-server.js +++ b/test/ipfs-factory/server.js @@ -20,7 +20,7 @@ module.exports = (callback) => { if (err) { return callback(err) } - require('./factory-server-routes')(http) + require('./server-routes')(http) callback(null, http) // note: http.stop(callback) to stop the server :) diff --git a/test/factory/factory-tasks.js b/test/ipfs-factory/tasks.js similarity index 84% rename from test/factory/factory-tasks.js rename to test/ipfs-factory/tasks.js index d89d10e1f..97847273e 100644 --- a/test/factory/factory-tasks.js +++ b/test/ipfs-factory/tasks.js @@ -1,7 +1,7 @@ 'use strict' const gulp = require('gulp') -const factoryServer = require('./factory-server') +const factoryServer = require('./server') let factory diff --git a/test/log.spec.js b/test/log.spec.js new file mode 100644 index 000000000..121b18b1b --- /dev/null +++ b/test/log.spec.js @@ -0,0 +1,48 @@ +/* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 8] */ +'use strict' + +const expect = require('chai').expect +const FactoryClient = require('./ipfs-factory/client') + +describe('.log', () => { + let ipfs + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + done() + }) + }) + + after((done) => fc.dismantle(done)) + + describe('Callback API', () => { + it('.log.tail', (done) => { + const req = ipfs.log.tail((err, res) => { + expect(err).to.not.exist + expect(req).to.exist + + res.once('data', (obj) => { + expect(obj).to.be.an('object') + done() + }) + }) + }) + }) + + describe('Promise API', () => { + it('.log.tail', () => { + return ipfs.log.tail() + .then((res) => { + res.once('data', (obj) => { + expect(obj).to.be.an('object') + }) + }) + }) + }) +}) diff --git a/test/interface-ipfs-core/ls.spec.js b/test/ls.spec.js similarity index 52% rename from test/interface-ipfs-core/ls.spec.js rename to test/ls.spec.js index fdb5be93e..6876989e7 100644 --- a/test/interface-ipfs-core/ls.spec.js +++ b/test/ls.spec.js @@ -6,12 +6,10 @@ const isNode = require('detect-node') const waterfall = require('async/waterfall') const path = require('path') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('./ipfs-factory/client') -describe('ls', function () { - if (!isNode) { - return - } +describe('.ls', () => { + if (!isNode) { return } let ipfs let fc @@ -24,7 +22,7 @@ describe('ls', function () { (cb) => fc.spawnNode(cb), (node, cb) => { ipfs = node - const filesPath = path.join(__dirname, '../fixtures/test-folder') + const filesPath = path.join(__dirname, '/fixtures/test-folder') ipfs.util.addFromFs(filesPath, { recursive: true }, cb) }, (hashes, cb) => { @@ -35,38 +33,38 @@ describe('ls', function () { ], done) }) - after((done) => { - fc.dismantle(done) - }) + after((done) => fc.dismantle(done)) - it('should correctly retrieve links', function (done) { - ipfs.ls(folder, (err, res) => { - expect(err).to.not.exist + describe('Callback API', () => { + it('should correctly retrieve links', function (done) { + ipfs.ls(folder, (err, res) => { + expect(err).to.not.exist - expect(res).to.have.a.property('Objects') - expect(res.Objects[0]).to.have.a.property('Links') - expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh') - done() + expect(res).to.have.a.property('Objects') + expect(res.Objects[0]).to.have.a.property('Links') + expect(res.Objects[0]).to.have.property('Hash', 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh') + done() + }) }) - }) - it('should correctly handle a nonexisting hash', function (done) { - ipfs.ls('surelynotavalidhashheh?', (err, res) => { - expect(err).to.exist - expect(res).to.not.exist - done() + it('should correctly handle a nonexisting hash', function (done) { + ipfs.ls('surelynotavalidhashheh?', (err, res) => { + expect(err).to.exist + expect(res).to.not.exist + done() + }) }) - }) - it('should correctly handle a nonexisting path', function (done) { - ipfs.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => { - expect(err).to.exist - expect(res).to.not.exist - done() + it('should correctly handle a nonexisting path', function (done) { + ipfs.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => { + expect(err).to.exist + expect(res).to.not.exist + done() + }) }) }) - describe('promise', () => { + describe('Promises API', () => { it('should correctly retrieve links', () => { return ipfs.ls(folder) .then((res) => { @@ -78,16 +76,12 @@ describe('ls', function () { it('should correctly handle a nonexisting hash', () => { return ipfs.ls('surelynotavalidhashheh?') - .catch((err) => { - expect(err).to.exist - }) + .catch((err) => expect(err).to.exist) }) it('should correctly handle a nonexisting path', () => { return ipfs.ls('QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there') - .catch((err) => { - expect(err).to.exist - }) + .catch((err) => expect(err).to.exist) }) }) }) diff --git a/test/mount.spec.js b/test/mount.spec.js new file mode 100644 index 000000000..19dc68fa3 --- /dev/null +++ b/test/mount.spec.js @@ -0,0 +1,5 @@ +/* eslint-env mocha */ +'use strict' + +// requires FUSE to be installed, not practical for testing +describe('.mount', () => {}) diff --git a/test/name.spec.js b/test/name.spec.js new file mode 100644 index 000000000..85d8405b7 --- /dev/null +++ b/test/name.spec.js @@ -0,0 +1,107 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const isNode = require('detect-node') +const series = require('async/series') +const loadFixture = require('aegir/fixtures') +const FactoryClient = require('./ipfs-factory/client') + +const testfile = isNode + ? loadFixture(__dirname, '/fixtures/testfile.txt') + : loadFixture(__dirname, 'fixtures/testfile.txt') + +describe('.name', () => { + let ipfs + let other + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + series([ + (cb) => { + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + cb() + }) + }, + (cb) => { + fc.spawnNode((err, node) => { + expect(err).to.not.exist + other = node + cb() + }) + }, + (cb) => { + ipfs.id((err, id) => { + expect(err).to.not.exist + const ma = id.addresses[0] + other.swarm.connect(ma, cb) + }) + } + ], done) + }) + + after((done) => fc.dismantle(done)) + + describe('Callback API', () => { + let name + + it('add file for testing', (done) => { + const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' + + ipfs.files.add(testfile, (err, res) => { + expect(err).to.not.exist + + expect(res).to.have.length(1) + expect(res[0].hash).to.equal(expectedMultihash) + expect(res[0].path).to.equal(expectedMultihash) + done() + }) + }) + + it('.name.publish', (done) => { + ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { + expect(err).to.not.exist + name = res + expect(name).to.exist + done() + }) + }) + + it('.name.resolve', (done) => { + ipfs.name.resolve(name.Name, (err, res) => { + expect(err).to.not.exist + expect(res).to.exist + expect(res).to.be.eql({ + Path: '/ipfs/' + name.Value + }) + done() + }) + }) + }) + + describe('Promise API', () => { + let name + + it('.name.publish', () => { + return ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') + .then((res) => { + name = res + expect(name).to.exist + }) + }) + + it('.name.resolve', () => { + return ipfs.name.resolve(name.Name) + .then((res) => { + expect(res).to.exist + expect(res).to.be.eql({ + Path: '/ipfs/' + name.Value + }) + }) + }) + }) +}) diff --git a/test/node.js b/test/node.js deleted file mode 100644 index ebfd1aada..000000000 --- a/test/node.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' - -require('./setup/setup-ipfs-api-clients') diff --git a/test/interface-ipfs-core/pin.spec.js b/test/pin.spec.js similarity index 84% rename from test/interface-ipfs-core/pin.spec.js rename to test/pin.spec.js index 3d05068b8..fbffe385d 100644 --- a/test/interface-ipfs-core/pin.spec.js +++ b/test/pin.spec.js @@ -3,7 +3,7 @@ 'use strict' const test = require('interface-ipfs-core') -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('./ipfs-factory/client') let fc diff --git a/test/ping.spec.js b/test/ping.spec.js new file mode 100644 index 000000000..c46e591bd --- /dev/null +++ b/test/ping.spec.js @@ -0,0 +1,77 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const series = require('async/series') +const FactoryClient = require('./ipfs-factory/client') + +describe.skip('.ping', () => { + let ipfs + let other + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + series([ + (cb) => { + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + cb() + }) + }, + (cb) => { + console.log('going to spawn second node') + fc.spawnNode((err, node) => { + expect(err).to.not.exist + other = node + cb() + }) + }, + (cb) => { + ipfs.id((err, id) => { + expect(err).to.not.exist + const ma = id.addresses[0] + other.swarm.connect(ma, cb) + }) + } + ], done) + }) + + after((done) => fc.dismantle(done)) + + describe('callback API', () => { + it('ping another peer', (done) => { + other.id((err, id) => { + expect(err).to.not.exist + + ipfs.ping(id.id, (err, res) => { + expect(err).to.not.exist + expect(res).to.have.a.property('Success') + expect(res).to.have.a.property('Time') + expect(res).to.have.a.property('Text') + expect(res.Text).to.contain('Average latency') + expect(res.Time).to.be.a('number') + done() + }) + }) + }) + }) + + describe('promise API', () => { + it('ping another peer', () => { + return other.id() + .then((id) => { + return ipfs.ping(id.id) + }) + .then((res) => { + expect(res).to.have.a.property('Success') + expect(res).to.have.a.property('Time') + expect(res).to.have.a.property('Text') + expect(res.Text).to.contain('Average latency') + expect(res.Time).to.be.a('number') + }) + }) + }) +}) diff --git a/test/refs.spec.js b/test/refs.spec.js new file mode 100644 index 000000000..d4e0ff9da --- /dev/null +++ b/test/refs.spec.js @@ -0,0 +1,80 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const isNode = require('detect-node') +const waterfall = require('async/waterfall') +const path = require('path') +const FactoryClient = require('./ipfs-factory/client') + +describe('.refs', () => { + if (!isNode) { return } + + let ipfs + let fc + let folder + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + waterfall([ + (cb) => fc.spawnNode(cb), + (node, cb) => { + ipfs = node + const filesPath = path.join(__dirname, '/fixtures/test-folder') + ipfs.util.addFromFs(filesPath, { recursive: true }, cb) + }, + (hashes, cb) => { + folder = hashes[hashes.length - 1].hash + expect(folder).to.be.eql('QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh') + cb() + } + ], done) + }) + + after((done) => fc.dismantle(done)) + + const result = [ + { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmcUYKmQxmTcFom4R4UZP7FWeQzgJkwcFn51XrvsMy7PE9 add', + Err: '' + }, { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmNeHxDfQfjVFyYj2iruvysLH9zpp78v3cu1s3BZq1j5hY cat', + Err: '' + }, { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmTYFLz5vsdMpq4XXw1a1pSxujJc9Z5V3Aw1Qg64d849Zy files', + Err: '' + }, { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu hello-link', + Err: '' + }, { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmU7wetVaAqc3Meurif9hcYBHGvQmL5QdpPJYBoZizyTNL ipfs-add', + Err: '' + }, { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmctZfSuegbi2TMFY2y3VQjxsH5JbRBu7XmiLfHNvshhio ls', + Err: '' + }, { + Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmbkMNB6rwfYAxRvnG9CWJ6cKKHEdq2ZKTozyF5FQ7H8Rs version', + Err: '' + } + ] + + describe('Callback API', () => { + it('refs', (done) => { + ipfs.refs(folder, {format: ' '}, (err, objs) => { + expect(err).to.not.exist + expect(objs).to.eql(result) + done() + }) + }) + }) + + describe('Promise API', () => { + it('refs', () => { + return ipfs.refs(folder, {format: ' '}) + .then((objs) => { + expect(objs).to.eql(result) + }) + }) + }) +}) diff --git a/test/interface-ipfs-core/repo.spec.js b/test/repo.spec.js similarity index 53% rename from test/interface-ipfs-core/repo.spec.js rename to test/repo.spec.js index 778e06426..6558774ce 100644 --- a/test/interface-ipfs-core/repo.spec.js +++ b/test/repo.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -const FactoryClient = require('../factory/factory-client') +const FactoryClient = require('./ipfs-factory/client') const expect = require('chai').expect describe('.repo', () => { @@ -22,30 +22,29 @@ describe('.repo', () => { fc.dismantle(done) }) - it('.repo.gc', (done) => { - ipfs.repo.gc((err, res) => { - expect(err).to.not.exist - expect(res).to.exist - done() + describe('Callback API', () => { + it('.repo.gc', (done) => { + ipfs.repo.gc((err, res) => { + expect(err).to.not.exist + expect(res).to.exist + done() + }) }) - }) - it('.repo.stat', (done) => { - ipfs.repo.stat((err, res) => { - expect(err).to.not.exist - expect(res).to.exist - expect(res).to.have.a.property('NumObjects') - expect(res).to.have.a.property('RepoSize') - done() + it('.repo.stat', (done) => { + ipfs.repo.stat((err, res) => { + expect(err).to.not.exist + expect(res).to.exist + expect(res).to.have.a.property('NumObjects') + expect(res).to.have.a.property('RepoSize') + done() + }) }) }) - describe('promise', () => { + describe('Promise API', () => { it('.repo.gc', () => { - return ipfs.repo.gc() - .then((res) => { - expect(res).to.exist - }) + return ipfs.repo.gc().then((res) => expect(res).to.exist) }) it('.repo.stat', () => { diff --git a/test/ipfs-api/request-api.spec.js b/test/request-api.spec.js similarity index 58% rename from test/ipfs-api/request-api.spec.js rename to test/request-api.spec.js index 9810a4e5d..b19c9f23a 100644 --- a/test/ipfs-api/request-api.spec.js +++ b/test/request-api.spec.js @@ -3,25 +3,24 @@ const expect = require('chai').expect const isNode = require('detect-node') -const ipfsAPI = require('./../../src/index.js') +const ipfsAPI = require('../src/index.js') -describe('ipfsAPI request tests', () => { +describe('\'deal with HTTP weirdness\' tests', () => { it('does not crash if no content-type header is provided', (done) => { - if (!isNode) { - return done() - } + if (!isNode) { return done() } // go-ipfs always (currently) adds a content-type header, even if no content is present, // the standard behaviour for an http-api is to omit this header if no content is present const server = require('http').createServer((req, res) => { res.writeHead(200) res.end() - }).listen(6001, () => { - ipfsAPI('/ip4/127.0.0.1/tcp/6001') - .config.replace('test/fixtures/r-config.json', (err) => { - expect(err).to.not.exist - server.close(done) - }) + }) + + server.listen(6001, () => { + ipfsAPI('/ip4/127.0.0.1/tcp/6001').config.replace('test/fixtures/r-config.json', (err) => { + expect(err).to.not.exist + server.close(done) + }) }) }) }) diff --git a/test/setup/setup-ipfs-api-clients.js b/test/setup/setup-ipfs-api-clients.js deleted file mode 100644 index eecb26787..000000000 --- a/test/setup/setup-ipfs-api-clients.js +++ /dev/null @@ -1,77 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const ipfsAPI = require('./../../src/index.js') -const apiAddrs = require('./tmp-disposable-nodes-addrs.json') - -// a, b, c -global.apiClients = {} - -const addrs = {} - -function connectNodes (done) { - let counter = 0 - - function collectAddr (key, cb) { - global.apiClients[key].id((err, id) => { - if (err) { - throw err - } - // note to self: HTTP API port !== Node port - addrs[key] = id.addresses[0] - cb() - }) - } - - function dial () { - global.apiClients.a.swarm.connect(addrs.b, (err, res) => { - if (err) { - throw err - } - global.apiClients.a.swarm.connect(addrs.c, (err) => { - if (err) { - throw err - } - done() - }) - }) - } - - function finish () { - counter++ - if (counter === 2) { - dial() - } - } - - collectAddr('b', finish) - collectAddr('c', finish) -} - -function disconnectNodes (done) { - global.apiClients.a.swarm.disconnect(addrs.b, (err) => { - if (err) { - throw err - } - global.apiClients.a.swarm.disconnect(addrs.c, (err) => { - if (err) { - throw err - } - done() - }) - }) -} - -before(function (done) { - this.timeout(20000) - - Object.keys(apiAddrs).forEach((key) => { - global.apiClients[key] = ipfsAPI(apiAddrs[key]) - }) - - connectNodes(done) -}) - -after(function (done) { - disconnectNodes(done) -}) diff --git a/test/setup/spawn-daemons.js b/test/setup/spawn-daemons.js deleted file mode 100644 index a747ffc2f..000000000 --- a/test/setup/spawn-daemons.js +++ /dev/null @@ -1,105 +0,0 @@ -'use strict' -// TODO reduce the callbacks nestness -/* eslint max-nested-callbacks: ["error", 8] */ - -const gulp = require('gulp') -const fs = require('fs') -const path = require('path') -const ipfsd = require('ipfsd-ctl') -const eachSeries = require('async/eachSeries') -const parallel = require('async/parallel') - -let daemons - -function startDisposableDaemons (callback) { - // a, b, c - const ipfsNodes = {} - - function startIndependentNode (nodes, key, cb) { - ipfsd.disposable((err, node) => { - if (err) { - return cb(err) - } - - nodes[key] = node - - console.log(' ipfs init done - (bootstrap and mdns off) - ' + key) - - const configValues = { - Bootstrap: [], - Discovery: {}, - 'API.HTTPHeaders.Access-Control-Allow-Origin': ['*'], - 'API.HTTPHeaders.Access-Control-Allow-Credentials': 'true', - 'API.HTTPHeaders.Access-Control-Allow-Methods': ['PUT', 'POST', 'GET'] - } - - eachSeries(Object.keys(configValues), (configKey, cb) => { - nodes[key].setConfig(configKey, JSON.stringify(configValues[configKey]), cb) - }, (err) => { - if (err) { - return cb(err) - } - - nodes[key].startDaemon(cb) - }) - }) - } - - parallel([ - (cb) => startIndependentNode(ipfsNodes, 'a', cb), - (cb) => startIndependentNode(ipfsNodes, 'b', cb), - (cb) => startIndependentNode(ipfsNodes, 'c', cb) - ], (err) => { - if (err) { - return callback(err) - } - const targetPath = path.join(__dirname, '/tmp-disposable-nodes-addrs.json') - fs.writeFileSync(targetPath, JSON.stringify({ - a: ipfsNodes.a.apiAddr, - b: ipfsNodes.b.apiAddr, - c: ipfsNodes.c.apiAddr - })) - callback(null, ipfsNodes) - }) -} - -function stopDisposableDaemons (ds, callback) { - function stopIPFSNode (node, cb) { - let nodeStopped - node.stopDaemon((err) => { - if (err) { - return cb(err) - } - if (!nodeStopped) { - nodeStopped = true - cb() - } - }) - } - - parallel([ - (cb) => stopIPFSNode(ds.a, cb), - (cb) => stopIPFSNode(ds.b, cb), - (cb) => stopIPFSNode(ds.c, cb) - ], callback) -} - -gulp.task('daemons:start', (done) => { - startDisposableDaemons((err, d) => { - if (err) { - return done(err) - } - daemons = d - done() - }) -}) - -gulp.task('daemons:stop', (done) => { - stopDisposableDaemons(daemons, (err) => { - if (err) { - return done(err) - } - daemons = null - done() - }) -}) diff --git a/test/interface-ipfs-core/update.spec.js b/test/update.spec.js similarity index 59% rename from test/interface-ipfs-core/update.spec.js rename to test/update.spec.js index d67e6abf2..986885bc7 100644 --- a/test/interface-ipfs-core/update.spec.js +++ b/test/update.spec.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ 'use strict' -describe('.update (currently disabled, wait for IPFS 0.4.0)', () => { +describe('.update (currently not available through ipfs-api)', () => { it('.update.apply') it('.update.check') it('.update.log') diff --git a/test/util.spec.js b/test/util.spec.js new file mode 100644 index 000000000..0df41afc6 --- /dev/null +++ b/test/util.spec.js @@ -0,0 +1,110 @@ +/* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 8] */ +'use strict' + +const expect = require('chai').expect +const isNode = require('detect-node') +const path = require('path') +const fs = require('fs') +const FactoryClient = require('./ipfs-factory/client') + +describe('.util', () => { + if (!isNode) { return } + + let ipfs + let fc + + before(function (done) { + this.timeout(20 * 1000) // slow CI + fc = new FactoryClient() + fc.spawnNode((err, node) => { + expect(err).to.not.exist + ipfs = node + done() + }) + }) + + after((done) => fc.dismantle(done)) + + describe('Callback API', () => { + it('.streamAdd', (done) => { + const tfpath = path.join(__dirname, '/fixtures/testfile.txt') + const rs = fs.createReadStream(tfpath) + rs.path = '' // clean the path for testing purposes + + ipfs.util.addFromStream(rs, (err, result) => { + expect(err).to.not.exist + expect(result.length).to.equal(1) + done() + }) + }) + + describe('.fsAdd should add', () => { + it('a directory', (done) => { + const filesPath = path.join(__dirname, '/fixtures/test-folder') + ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => { + expect(err).to.not.exist + expect(result.length).to.be.above(8) + done() + }) + }) + + it('a directory with an odd name', (done) => { + const filesPath = path.join(__dirname, '/fixtures/weird name folder [v0]') + ipfs.util.addFromFs(filesPath, { recursive: true }, (err, result) => { + expect(err).to.not.exist + expect(result.length).to.be.above(8) + done() + }) + }) + + it('add and ignore a directory', (done) => { + const filesPath = path.join(__dirname, '/fixtures/test-folder') + ipfs.util.addFromFs(filesPath, { recursive: true, ignore: ['files/**'] }, (err, result) => { + expect(err).to.not.exist + expect(result.length).to.be.below(9) + done() + }) + }) + + it('a file', (done) => { + const filePath = path.join(__dirname, '/fixtures/testfile.txt') + ipfs.util.addFromFs(filePath, (err, result) => { + expect(err).to.not.exist + expect(result.length).to.be.equal(1) + expect(result[0].path).to.be.equal('testfile.txt') + done() + }) + }) + + it('a hidden file in a directory', (done) => { + const filesPath = path.join(__dirname, '/fixtures/test-folder') + ipfs.util.addFromFs(filesPath, { recursive: true, hidden: true }, (err, result) => { + expect(err).to.not.exist + expect(result.length).to.be.above(10) + expect(result.map(object => object.path)).to.include('test-folder/.hiddenTest.txt') + expect(result.map(object => object.hash)).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt') + done() + }) + }) + }) + + it('.urlAdd http', (done) => { + ipfs.util.addFromURL('http://example.com/', (err, result) => { + expect(err).to.not.exist + expect(result.length).to.equal(1) + done() + }) + }) + + it('.urlAdd https', (done) => { + ipfs.util.addFromURL('https://example.com/', (err, result) => { + expect(err).to.not.exist + expect(result.length).to.equal(1) + done() + }) + }) + }) + + describe('Promise API', () => {}) +})