From 0bee89f7ca5d4e6d904f2f145bd6a2015793396f Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 15 Aug 2016 02:05:34 +0100 Subject: [PATCH] refactor(tests): make each feature test isolated (launchable by itself --- test/interface-ipfs-core/block.spec.js | 35 ++++++++--- test/interface-ipfs-core/bootstrap.spec.js | 55 +++++++++++------ test/interface-ipfs-core/commands.spec.js | 23 +++++++- test/interface-ipfs-core/diag.spec.js | 31 +++++++--- test/interface-ipfs-core/files.spec.js | 68 +++++++++++++--------- test/interface-ipfs-core/get.spec.js | 46 ++++++++++++--- test/interface-ipfs-core/id.spec.js | 23 +++++++- test/interface-ipfs-core/index.spec.js | 12 ---- test/interface-ipfs-core/log.spec.js | 60 +++++++++++-------- test/interface-ipfs-core/ls.spec.js | 36 +++++++++--- test/interface-ipfs-core/name.spec.js | 17 ++++++ test/interface-ipfs-core/pin.spec.js | 56 ++++++++++++++---- test/interface-ipfs-core/refs.spec.js | 27 +++++++-- test/interface-ipfs-core/repo.spec.js | 27 +++++++-- test/interface-ipfs-core/send.spec.js | 6 -- test/interface-ipfs-core/version.spec.js | 31 +++++++--- 16 files changed, 400 insertions(+), 153 deletions(-) delete mode 100644 test/interface-ipfs-core/index.spec.js delete mode 100644 test/interface-ipfs-core/send.spec.js diff --git a/test/interface-ipfs-core/block.spec.js b/test/interface-ipfs-core/block.spec.js index 5fedd8f0e..2bfa89e09 100644 --- a/test/interface-ipfs-core/block.spec.js +++ b/test/interface-ipfs-core/block.spec.js @@ -1,22 +1,39 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -/* globals apiClients */ 'use strict' +const FactoryClient = require('../factory/factory-client') const expect = require('chai').expect describe('.block', () => { + 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) + }) + const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ' const blorb = Buffer('blorb') it('returns an error when putting an array of files', () => { - return apiClients.a.block.put([blorb, blorb], (err) => { + return ipfs.block.put([blorb, blorb], (err) => { expect(err).to.be.an.instanceof(Error) }) }) it('block.put', (done) => { - apiClients.a.block.put(blorb, (err, res) => { + ipfs.block.put(blorb, (err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ') done() @@ -24,7 +41,7 @@ describe('.block', () => { }) it('block.get', (done) => { - apiClients.a.block.get(blorbKey, (err, res) => { + ipfs.block.get(blorbKey, (err, res) => { expect(err).to.not.exist let buf = '' @@ -38,7 +55,7 @@ describe('.block', () => { }) it('block.stat', (done) => { - apiClients.a.block.stat(blorbKey, (err, res) => { + ipfs.block.stat(blorbKey, (err, res) => { expect(err).to.not.exist expect(res).to.have.property('Key') expect(res).to.have.property('Size') @@ -48,21 +65,21 @@ describe('.block', () => { describe('promise', () => { it('returns an error when putting an array of files', () => { - return apiClients.a.block.put([blorb, blorb]) + return ipfs.block.put([blorb, blorb]) .catch((err) => { expect(err).to.be.an.instanceof(Error) }) }) it('block.put', () => { - return apiClients.a.block.put(blorb) + return ipfs.block.put(blorb) .then((res) => { expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ') }) }) it('block.get', (done) => { - apiClients.a.block.get(blorbKey) + ipfs.block.get(blorbKey) .then((res) => { let buf = '' res @@ -76,7 +93,7 @@ describe('.block', () => { }) it('block.stat', () => { - return apiClients.a.block.stat(blorbKey) + return ipfs.block.stat(blorbKey) .then((res) => { expect(res).to.have.property('Key') expect(res).to.have.property('Size') diff --git a/test/interface-ipfs-core/bootstrap.spec.js b/test/interface-ipfs-core/bootstrap.spec.js index 8cecb7978..48448a5b8 100644 --- a/test/interface-ipfs-core/bootstrap.spec.js +++ b/test/interface-ipfs-core/bootstrap.spec.js @@ -1,33 +1,50 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect +const FactoryClient = require('../factory/factory-client') const invalidArg = 'this/Is/So/Invalid/' const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' describe('.bootstrap', () => { + 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) + }) + let peers describe('.add', () => { it('returns an error when called without args or options', (done) => { - return apiClients.a.bootstrap.add(null, (err) => { + return ipfs.bootstrap.add(null, (err) => { expect(err).to.be.an.instanceof(Error) done() }) }) it('returns an error when called with an invalid arg', (done) => { - return apiClients.a.bootstrap.add(invalidArg, (err) => { + return 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) => { - return apiClients.a.bootstrap.add(validIp4, (err, res) => { + return ipfs.bootstrap.add(validIp4, (err, res) => { expect(err).to.not.exist expect(res).to.be.eql({ Peers: [validIp4] }) peers = res.Peers @@ -38,7 +55,7 @@ describe('.bootstrap', () => { }) it('returns a list of bootstrap peers when called with the default option', (done) => { - return apiClients.a.bootstrap.add(null, { default: true }, (err, res) => { + return ipfs.bootstrap.add(null, { default: true }, (err, res) => { expect(err).to.not.exist peers = res.Peers expect(peers).to.exist @@ -50,7 +67,7 @@ describe('.bootstrap', () => { describe('.list', () => { it('returns a list of peers', (done) => { - return apiClients.a.bootstrap.list((err, res) => { + return ipfs.bootstrap.list((err, res) => { expect(err).to.not.exist peers = res.Peers expect(peers).to.exist @@ -61,14 +78,14 @@ describe('.bootstrap', () => { describe('.rm', () => { it('returns an error when called with an invalid arg', (done) => { - return apiClients.a.bootstrap.rm(invalidArg, (err) => { + return 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) => { - return apiClients.a.bootstrap.rm(null, (err, res) => { + return ipfs.bootstrap.rm(null, (err, res) => { expect(err).to.not.exist peers = res.Peers expect(peers).to.exist @@ -78,7 +95,7 @@ describe('.bootstrap', () => { }) it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { - return apiClients.a.bootstrap.rm(null, (err, res) => { + return ipfs.bootstrap.rm(null, (err, res) => { expect(err).to.not.exist peers = res.Peers expect(peers).to.exist @@ -88,7 +105,7 @@ describe('.bootstrap', () => { }) it('returns list of all peers removed when all option is passed', (done) => { - return apiClients.a.bootstrap.rm(null, { all: true }, (err, res) => { + return ipfs.bootstrap.rm(null, { all: true }, (err, res) => { expect(err).to.not.exist peers = res.Peers expect(peers).to.exist @@ -100,21 +117,21 @@ describe('.bootstrap', () => { describe('.promise', () => { describe('.add', () => { it('returns an error when called without args or options', () => { - return apiClients.a.bootstrap.add(null) + return ipfs.bootstrap.add(null) .catch((err) => { expect(err).to.be.an.instanceof(Error) }) }) it('returns an error when called with an invalid arg', () => { - return apiClients.a.bootstrap.add(invalidArg) + return ipfs.bootstrap.add(invalidArg) .catch((err) => { expect(err).to.be.an.instanceof(Error) }) }) it('returns a list of peers when called with a valid arg (ip4)', () => { - return apiClients.a.bootstrap.add(validIp4) + return ipfs.bootstrap.add(validIp4) .then((res) => { expect(res).to.be.eql({ Peers: [validIp4] }) peers = res.Peers @@ -124,7 +141,7 @@ describe('.bootstrap', () => { }) it('returns a list of default peers when called with the default option', () => { - return apiClients.a.bootstrap.add(null, { default: true }) + return ipfs.bootstrap.add(null, { default: true }) .then((res) => { peers = res.Peers expect(peers).to.exist @@ -135,7 +152,7 @@ describe('.bootstrap', () => { describe('.list', () => { it('returns a list of peers', () => { - return apiClients.a.bootstrap.list() + return ipfs.bootstrap.list() .then((res) => { peers = res.Peers expect(peers).to.exist @@ -145,14 +162,14 @@ describe('.bootstrap', () => { describe('.rm', () => { it('returns an error when called with an invalid arg', () => { - return apiClients.a.bootstrap.rm(invalidArg) + return ipfs.bootstrap.rm(invalidArg) .catch((err) => { expect(err).to.be.an.instanceof(Error) }) }) it('returns empty list when called without an arg or options', () => { - return apiClients.a.bootstrap.rm(null) + return ipfs.bootstrap.rm(null) .then((res) => { peers = res.Peers expect(peers).to.exist @@ -161,7 +178,7 @@ describe('.bootstrap', () => { }) it('returns list containing the peer removed when called with a valid arg (ip4)', () => { - return apiClients.a.bootstrap.rm(null) + return ipfs.bootstrap.rm(null) .then((res) => { peers = res.Peers expect(peers).to.exist @@ -170,7 +187,7 @@ describe('.bootstrap', () => { }) it('returns list of all peers removed when all option is passed', () => { - return apiClients.a.bootstrap.rm(null, { all: true }) + return ipfs.bootstrap.rm(null, { all: true }) .then((res) => { peers = res.Peers expect(peers).to.exist diff --git a/test/interface-ipfs-core/commands.spec.js b/test/interface-ipfs-core/commands.spec.js index a3fff5556..e18b0ca24 100644 --- a/test/interface-ipfs-core/commands.spec.js +++ b/test/interface-ipfs-core/commands.spec.js @@ -1,12 +1,29 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect +const FactoryClient = require('../factory/factory-client') describe('.commands', () => { + 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('lists commands', (done) => { - apiClients.a.commands((err, res) => { + ipfs.commands((err, res) => { expect(err).to.not.exist expect(res).to.exist done() @@ -15,7 +32,7 @@ describe('.commands', () => { describe('promise', () => { it('lists commands', () => { - return apiClients.a.commands() + return ipfs.commands() .then((res) => { expect(res).to.exist }) diff --git a/test/interface-ipfs-core/diag.spec.js b/test/interface-ipfs-core/diag.spec.js index a7097f7e5..198248343 100644 --- a/test/interface-ipfs-core/diag.spec.js +++ b/test/interface-ipfs-core/diag.spec.js @@ -1,12 +1,29 @@ /* eslint-env mocha */ -/* globals apiClients */ '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) => { - apiClients.a.diag.net((err, res) => { + ipfs.diag.net((err, res) => { expect(err).to.not.exist expect(res).to.exist done() @@ -14,7 +31,7 @@ describe('.diag', () => { }) it('.diag.sys', (done) => { - apiClients.a.diag.sys((err, res) => { + ipfs.diag.sys((err, res) => { expect(err).to.not.exist expect(res).to.exist expect(res).to.have.a.property('memory') @@ -24,7 +41,7 @@ describe('.diag', () => { }) it('.diag.cmds', (done) => { - apiClients.a.diag.cmds((err, res) => { + ipfs.diag.cmds((err, res) => { expect(err).to.not.exist expect(res).to.exist done() @@ -33,14 +50,14 @@ describe('.diag', () => { describe('promise', () => { it('.diag.net', () => { - return apiClients.a.diag.net() + return ipfs.diag.net() .then((res) => { expect(res).to.exist }) }) it('.diag.sys', () => { - return apiClients.a.diag.sys() + return ipfs.diag.sys() .then((res) => { expect(res).to.exist expect(res).to.have.a.property('memory') @@ -49,7 +66,7 @@ describe('.diag', () => { }) it('.diag.cmds', () => { - return apiClients.a.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 index d40187b6a..bed5c1506 100644 --- a/test/interface-ipfs-core/files.spec.js +++ b/test/interface-ipfs-core/files.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect @@ -28,10 +27,27 @@ 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' - apiClients.a.files.add(testfile, (err, res) => { + ipfs.files.add(testfile, (err, res) => { expect(err).to.not.exist expect(res).to.have.length(1) @@ -42,14 +58,14 @@ describe('.files (pseudo mfs)', () => { }) it('files.mkdir', (done) => { - apiClients.a.files.mkdir('/test-folder', function (err) { + ipfs.files.mkdir('/test-folder', function (err) { expect(err).to.not.exist done() }) }) it('files.cp', (done) => { - apiClients.a.files + ipfs.files .cp(['/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file'], (err) => { expect(err).to.not.exist done() @@ -57,7 +73,7 @@ describe('.files (pseudo mfs)', () => { }) it('files.ls', (done) => { - apiClients.a.files.ls('/test-folder', (err, res) => { + ipfs.files.ls('/test-folder', (err, res) => { expect(err).to.not.exist expect(res.Entries.length).to.equal(1) done() @@ -65,11 +81,11 @@ describe('.files (pseudo mfs)', () => { }) it('files.write', (done) => { - apiClients.a.files + ipfs.files .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}, (err) => { expect(err).to.not.exist - apiClients.a.files.read('/test-folder/test-file-2.txt', (err, stream) => { + ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { expect(err).to.not.exist let buf = '' @@ -89,11 +105,11 @@ describe('.files (pseudo mfs)', () => { }) it('files.write without options', (done) => { - apiClients.a.files + ipfs.files .write('/test-folder/test-file-2.txt', new Buffer('hello world'), (err) => { expect(err).to.not.exist - apiClients.a.files.read('/test-folder/test-file-2.txt', (err, stream) => { + ipfs.files.read('/test-folder/test-file-2.txt', (err, stream) => { expect(err).to.not.exist let buf = '' @@ -113,7 +129,7 @@ describe('.files (pseudo mfs)', () => { }) it('files.stat', (done) => { - apiClients.a.files.stat('/test-folder/test-file', (err, res) => { + ipfs.files.stat('/test-folder/test-file', (err, res) => { expect(err).to.not.exist expect(res).to.deep.equal({ Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', @@ -128,7 +144,7 @@ describe('.files (pseudo mfs)', () => { }) it('files.stat file that does not exist', (done) => { - apiClients.a.files.stat('/test-folder/does-not-exist', (err, res) => { + ipfs.files.stat('/test-folder/does-not-exist', (err, res) => { expect(err).to.exist if (err.code === 0) { return done() @@ -142,7 +158,7 @@ describe('.files (pseudo mfs)', () => { return done() } - apiClients.a.files.read('/test-folder/test-file', (err, stream) => { + ipfs.files.read('/test-folder/test-file', (err, stream) => { expect(err).to.not.exist let buf = '' stream @@ -160,14 +176,14 @@ describe('.files (pseudo mfs)', () => { }) it('files.rm without options', (done) => { - apiClients.a.files.rm('/test-folder/test-file-2.txt', (err) => { + ipfs.files.rm('/test-folder/test-file-2.txt', (err) => { expect(err).to.not.exist done() }) }) it('files.rm', (done) => { - apiClients.a.files.rm('/test-folder', {recursive: true}, (err) => { + ipfs.files.rm('/test-folder', {recursive: true}, (err) => { expect(err).to.not.exist done() }) @@ -175,26 +191,26 @@ describe('.files (pseudo mfs)', () => { describe('promise', () => { it('files.mkdir', () => { - return apiClients.a.files.mkdir('/test-folder') + return ipfs.files.mkdir('/test-folder') }) it('files.cp', () => { - return apiClients.a.files + return ipfs.files .cp(['/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', '/test-folder/test-file']) }) it('files.ls', () => { - return apiClients.a.files.ls('/test-folder') + return ipfs.files.ls('/test-folder') .then((res) => { expect(res.Entries.length).to.equal(1) }) }) it('files.write', (done) => { - apiClients.a.files + ipfs.files .write('/test-folder/test-file-2.txt', new Buffer('hello world'), {create: true}) .then(() => { - return apiClients.a.files.read('/test-folder/test-file-2.txt') + return ipfs.files.read('/test-folder/test-file-2.txt') }) .then((stream) => { let buf = '' @@ -214,10 +230,10 @@ describe('.files (pseudo mfs)', () => { }) it('files.write without options', (done) => { - apiClients.a.files + ipfs.files .write('/test-folder/test-file-2.txt', new Buffer('hello world')) .then(() => { - return apiClients.a.files.read('/test-folder/test-file-2.txt') + return ipfs.files.read('/test-folder/test-file-2.txt') }) .then((stream) => { let buf = '' @@ -237,7 +253,7 @@ describe('.files (pseudo mfs)', () => { }) it('files.stat', () => { - return apiClients.a.files.stat('/test-folder/test-file') + return ipfs.files.stat('/test-folder/test-file') .then((res) => { expect(res).to.deep.equal({ Hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', @@ -250,7 +266,7 @@ describe('.files (pseudo mfs)', () => { }) it('files.stat file that does not exist', () => { - return apiClients.a.files.stat('/test-folder/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) @@ -262,7 +278,7 @@ describe('.files (pseudo mfs)', () => { return done() } - apiClients.a.files.read('/test-folder/test-file') + ipfs.files.read('/test-folder/test-file') .then((stream) => { let buf = '' stream @@ -280,11 +296,11 @@ describe('.files (pseudo mfs)', () => { }) it('files.rm without options', () => { - return apiClients.a.files.rm('/test-folder/test-file-2.txt') + return ipfs.files.rm('/test-folder/test-file-2.txt') }) it('files.rm', () => { - return apiClients.a.files.rm('/test-folder', {recursive: true}) + return ipfs.files.rm('/test-folder', {recursive: true}) }) }) }) diff --git a/test/interface-ipfs-core/get.spec.js b/test/interface-ipfs-core/get.spec.js index 2bf1f9f73..b989811c7 100644 --- a/test/interface-ipfs-core/get.spec.js +++ b/test/interface-ipfs-core/get.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -/* globals apiClients */ 'use strict' @@ -11,6 +10,7 @@ const concat = require('concat-stream') const through = require('through2') const streamEqual = require('stream-equal') const path = require('path') +const FactoryClient = require('../factory/factory-client') const testfile = fs.readFileSync(path.join(__dirname, '/../data/testfile.txt')) @@ -22,8 +22,38 @@ if (isNode) { } describe('.get', () => { + 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('get with no compression args', (done) => { - apiClients.a + ipfs .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { expect(err).to.not.exist @@ -46,7 +76,7 @@ describe('.get', () => { }) it('get with archive true', (done) => { - apiClients.a + ipfs .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {archive: true}, (err, res) => { expect(err).to.not.exist @@ -69,7 +99,7 @@ describe('.get', () => { }) it('get err with out of range compression level', (done) => { - apiClients.a + 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') @@ -78,7 +108,7 @@ describe('.get', () => { }) it('get with compression level', (done) => { - apiClients.a + ipfs .get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {compress: true, 'compression-level': 1}, (err, res) => { expect(err).to.not.exist done() @@ -93,7 +123,7 @@ describe('.get', () => { const bigFile = fs.readFileSync(tfbPath) const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' - apiClients.a.files.add(bigFile, (err, res) => { + ipfs.files.add(bigFile, (err, res) => { expect(err).to.not.exist expect(res).to.have.length(1) @@ -108,7 +138,7 @@ describe('.get', () => { return done() } - apiClients.a.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, files) => { + ipfs.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, files) => { expect(err).to.not.exist files.on('data', (file) => { @@ -124,7 +154,7 @@ describe('.get', () => { describe('promise', () => { it('get', (done) => { - apiClients.a.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') + ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') .then((files) => { files.on('data', (file) => { let buf = '' diff --git a/test/interface-ipfs-core/id.spec.js b/test/interface-ipfs-core/id.spec.js index 26187e67c..936910853 100644 --- a/test/interface-ipfs-core/id.spec.js +++ b/test/interface-ipfs-core/id.spec.js @@ -1,12 +1,29 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect +const FactoryClient = require('../factory/factory-client') describe('.id', () => { + 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('id', (done) => { - apiClients.a.id((err, res) => { + ipfs.id((err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('ID') expect(res).to.have.a.property('PublicKey') @@ -16,7 +33,7 @@ describe('.id', () => { describe('promise', () => { it('id', () => { - return apiClients.a.id() + return ipfs.id() .then((res) => { expect(res).to.have.a.property('ID') expect(res).to.have.a.property('PublicKey') diff --git a/test/interface-ipfs-core/index.spec.js b/test/interface-ipfs-core/index.spec.js deleted file mode 100644 index a92b33245..000000000 --- a/test/interface-ipfs-core/index.spec.js +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-env mocha */ -/* globals apiClients */ -'use strict' - -const expect = require('chai').expect - -describe('API', () => { - it('has the api object', () => { - expect(apiClients.a).to.exist - expect(apiClients.a).to.have.a.property('id') - }) -}) diff --git a/test/interface-ipfs-core/log.spec.js b/test/interface-ipfs-core/log.spec.js index 65ac3c0ac..11710b780 100644 --- a/test/interface-ipfs-core/log.spec.js +++ b/test/interface-ipfs-core/log.spec.js @@ -1,42 +1,54 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 8] */ -/* globals apiClients */ '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/) -describe('.log', () => { - it('.log.tail', (done) => { - if (isPhantom) { - return done() - } - const req = apiClients.a.log.tail((err, res) => { - expect(err).to.not.exist - expect(req).to.exist - - res.once('data', (obj) => { - expect(obj).to.be.an('object') +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() }) }) - }) - describe('promise', () => { - it('.log.tail', () => { - if (isPhantom) { - return - } + after((done) => { + fc.dismantle(done) + }) - return apiClients.a.log.tail() - .then((res) => { - res.once('data', (obj) => { - expect(obj).to.be.an('object') - }) + 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/ls.spec.js b/test/interface-ipfs-core/ls.spec.js index 2dbcd075a..43082cb66 100644 --- a/test/interface-ipfs-core/ls.spec.js +++ b/test/interface-ipfs-core/ls.spec.js @@ -1,15 +1,33 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect const isNode = require('detect-node') - +const FactoryClient = require('../factory/factory-client') describe('ls', function () { + 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('should correctly retrieve links', function (done) { - if (!isNode) return done() + if (!isNode) { + return done() + } - apiClients.a.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG', (err, res) => { + ipfs.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG', (err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('Objects') @@ -20,7 +38,7 @@ describe('ls', function () { }) it('should correctly handle a nonexisting hash', function (done) { - apiClients.a.ls('surelynotavalidhashheh?', (err, res) => { + ipfs.ls('surelynotavalidhashheh?', (err, res) => { expect(err).to.exist expect(res).to.not.exist done() @@ -30,7 +48,7 @@ describe('ls', function () { it('should correctly handle a nonexisting path', function (done) { if (!isNode) return done() - apiClients.a.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => { + ipfs.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => { expect(err).to.exist expect(res).to.not.exist done() @@ -41,7 +59,7 @@ describe('ls', function () { it('should correctly retrieve links', () => { if (!isNode) return - return apiClients.a.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG') + return ipfs.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG') .then((res) => { expect(res).to.have.a.property('Objects') expect(res.Objects[0]).to.have.a.property('Links') @@ -50,7 +68,7 @@ describe('ls', function () { }) it('should correctly handle a nonexisting hash', () => { - return apiClients.a.ls('surelynotavalidhashheh?') + return ipfs.ls('surelynotavalidhashheh?') .catch((err) => { expect(err).to.exist }) @@ -59,7 +77,7 @@ describe('ls', function () { it('should correctly handle a nonexisting path', () => { if (!isNode) return - return apiClients.a.ls('QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there') + return ipfs.ls('QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there') .catch((err) => { expect(err).to.exist }) diff --git a/test/interface-ipfs-core/name.spec.js b/test/interface-ipfs-core/name.spec.js index 6cfd93788..4e3e9194f 100644 --- a/test/interface-ipfs-core/name.spec.js +++ b/test/interface-ipfs-core/name.spec.js @@ -3,10 +3,27 @@ 'use strict' const expect = require('chai').expect +const fs = require('fs') +const path = require('path') + +const testfile = fs.readFileSync(path.join(__dirname, '/../data/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 diff --git a/test/interface-ipfs-core/pin.spec.js b/test/interface-ipfs-core/pin.spec.js index 56be6bf2a..f49de1c9b 100644 --- a/test/interface-ipfs-core/pin.spec.js +++ b/test/interface-ipfs-core/pin.spec.js @@ -1,12 +1,46 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect +const FactoryClient = require('../factory/factory-client') +const fs = require('fs') +const path = require('path') + +const testfile = fs.readFileSync(path.join(__dirname, '/../data/testfile.txt')) describe('.pin', () => { + 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('.pin.add', (done) => { - apiClients.b.pin.add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}, (err, res) => { + ipfs.pin.add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}, (err, res) => { expect(err).to.not.exist expect(res.Pins[0]).to.be.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') done() @@ -14,7 +48,7 @@ describe('.pin', () => { }) it('.pin.list', (done) => { - apiClients.b.pin.list((err, res) => { + ipfs.pin.list((err, res) => { expect(err).to.not.exist expect(res).to.exist done() @@ -22,7 +56,7 @@ describe('.pin', () => { }) it('.pin.list hash', (done) => { - apiClients.b.pin.list({hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'}, (err, res) => { + ipfs.pin.list({hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'}, (err, res) => { expect(err).to.not.exist expect(res).to.exist done() @@ -30,10 +64,10 @@ describe('.pin', () => { }) it('.pin.remove', (done) => { - apiClients.b.pin.remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}, (err, res) => { + ipfs.pin.remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}, (err, res) => { expect(err).to.not.exist expect(res).to.exist - apiClients.b.pin.list('direct', (err, res) => { + ipfs.pin.list('direct', (err, res) => { expect(err).to.not.exist expect(res).to.exist expect(res.Keys).to.be.empty @@ -44,7 +78,7 @@ describe('.pin', () => { describe('promise', () => { it('.pin.add', () => { - return apiClients.b.pin + return ipfs.pin .add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}) .then((res) => { expect(res.Pins[0]).to.be.equal('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') @@ -52,14 +86,14 @@ describe('.pin', () => { }) it('.pin.list', () => { - return apiClients.b.pin.list() + return ipfs.pin.list() .then((res) => { expect(res).to.exist }) }) it('.pin.list hash', () => { - return apiClients.b.pin.list({ + return ipfs.pin.list({ hash: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' }) .then((res) => { @@ -68,11 +102,11 @@ describe('.pin', () => { }) it('.pin.remove', () => { - return apiClients.b.pin + return ipfs.pin .remove('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {recursive: false}) .then((res) => { expect(res).to.exist - return apiClients.b.pin.list('direct') + return ipfs.pin.list('direct') }) .then((res) => { expect(res).to.exist diff --git a/test/interface-ipfs-core/refs.spec.js b/test/interface-ipfs-core/refs.spec.js index d8dad1345..e687290e6 100644 --- a/test/interface-ipfs-core/refs.spec.js +++ b/test/interface-ipfs-core/refs.spec.js @@ -1,11 +1,28 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect const isNode = require('detect-node') +const FactoryClient = require('../factory/factory-client') describe('.refs', () => { + 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) + }) + const folder = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' const result = [{ Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V about', @@ -32,7 +49,7 @@ describe('.refs', () => { return done() } - apiClients.a.refs(folder, {format: ' '}, (err, objs) => { + ipfs.refs(folder, {format: ' '}, (err, objs) => { expect(err).to.not.exist expect(objs).to.eql(result) @@ -42,9 +59,11 @@ describe('.refs', () => { describe('promise', () => { it('refs', () => { - if (!isNode) return + if (!isNode) { + return + } - return apiClients.a.refs(folder, {format: ' '}) + return ipfs.refs(folder, {format: ' '}) .then((objs) => { expect(objs).to.eql(result) }) diff --git a/test/interface-ipfs-core/repo.spec.js b/test/interface-ipfs-core/repo.spec.js index 6930bcc4f..778e06426 100644 --- a/test/interface-ipfs-core/repo.spec.js +++ b/test/interface-ipfs-core/repo.spec.js @@ -1,12 +1,29 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' +const FactoryClient = require('../factory/factory-client') const expect = require('chai').expect describe('.repo', () => { + 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('.repo.gc', (done) => { - apiClients.a.repo.gc((err, res) => { + ipfs.repo.gc((err, res) => { expect(err).to.not.exist expect(res).to.exist done() @@ -14,7 +31,7 @@ describe('.repo', () => { }) it('.repo.stat', (done) => { - apiClients.a.repo.stat((err, res) => { + ipfs.repo.stat((err, res) => { expect(err).to.not.exist expect(res).to.exist expect(res).to.have.a.property('NumObjects') @@ -25,14 +42,14 @@ describe('.repo', () => { describe('promise', () => { it('.repo.gc', () => { - return apiClients.a.repo.gc() + return ipfs.repo.gc() .then((res) => { expect(res).to.exist }) }) it('.repo.stat', () => { - return apiClients.a.repo.stat() + return ipfs.repo.stat() .then((res) => { expect(res).to.exist expect(res).to.have.a.property('NumObjects') diff --git a/test/interface-ipfs-core/send.spec.js b/test/interface-ipfs-core/send.spec.js deleted file mode 100644 index 9714a72d3..000000000 --- a/test/interface-ipfs-core/send.spec.js +++ /dev/null @@ -1,6 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -describe('.send', () => { - it('used by every command') -}) diff --git a/test/interface-ipfs-core/version.spec.js b/test/interface-ipfs-core/version.spec.js index c7b9b0298..c07ed5599 100644 --- a/test/interface-ipfs-core/version.spec.js +++ b/test/interface-ipfs-core/version.spec.js @@ -1,14 +1,31 @@ /* eslint-env mocha */ -/* globals apiClients */ 'use strict' const expect = require('chai').expect +const FactoryClient = require('../factory/factory-client') describe('.version', () => { + 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) + }) + // note, IPFS HTTP-API returns always the same object, the filtering // happens on the CLI it('checks the version', (done) => { - apiClients.a.version((err, res) => { + ipfs.version((err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('Version') expect(res).to.have.a.property('Commit') @@ -18,7 +35,7 @@ describe('.version', () => { }) it('with number option', (done) => { - apiClients.a.version({number: true}, (err, res) => { + ipfs.version({number: true}, (err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('Version') expect(res).to.have.a.property('Commit') @@ -28,7 +45,7 @@ describe('.version', () => { }) it('with commit option', (done) => { - apiClients.a.version({commit: true}, (err, res) => { + ipfs.version({commit: true}, (err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('Version') expect(res).to.have.a.property('Commit') @@ -38,7 +55,7 @@ describe('.version', () => { }) it('with repo option', (done) => { - apiClients.a.version({commit: true}, (err, res) => { + ipfs.version({commit: true}, (err, res) => { expect(err).to.not.exist expect(res).to.have.a.property('Version') expect(res).to.have.a.property('Commit') @@ -49,7 +66,7 @@ describe('.version', () => { describe('promise', () => { it('checks the version', () => { - return apiClients.a.version() + return ipfs.version() .then((res) => { expect(res).to.have.a.property('Version') expect(res).to.have.a.property('Commit') @@ -58,7 +75,7 @@ describe('.version', () => { }) it('with number option', () => { - return apiClients.a.version({number: true}) + return ipfs.version({number: true}) .then((res) => { expect(res).to.have.a.property('Version') expect(res).to.have.a.property('Commit')