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/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/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