From 3566712906b4ed321dcc0a7c7bcd601879c65ca1 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 30 Nov 2018 18:55:55 +0000 Subject: [PATCH 1/3] fix: tests using files --- test/files.js | 2 +- test/utils/circuit.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/files.js b/test/files.js index efee4c6b..146f0c8e 100644 --- a/test/files.js +++ b/test/files.js @@ -196,7 +196,7 @@ describe('files', function () { describe('has the same hashes for', () => { const testHashesAreEqual = (daemon, data, options) => { - return daemon.api.files.add(data, options) + return daemon.api.add(data, options) .then(files => files[0].hash) } diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 36e1352c..6ec50832 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -98,8 +98,8 @@ exports.createGoNode = (addrs, callback) => { const data = crypto.randomBytes(128) exports.send = (nodeA, nodeB, callback) => { waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), + (cb) => nodeA.add(data, cb), + (res, cb) => nodeB.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() From f68d018ce021bcd87e8fe8c8250096cf9f333ac9 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 30 Nov 2018 18:55:55 +0000 Subject: [PATCH 2/3] fix: tests using files --- package.json | 2 +- test/files.js | 4 ++-- test/utils/circuit.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e6d73b29..1984bf3f 100644 --- a/package.json +++ b/package.json @@ -51,8 +51,8 @@ "go-ipfs-dep": "~0.4.18", "hat": "0.0.3", "ipfs": "~0.33.0", - "ipfs-api": "^26.1.2", "ipfs-unixfs": "~0.1.16", + "ipfs-http-client": "^27.0.0", "ipfsd-ctl": "~0.40.0", "left-pad": "^1.3.0", "libp2p-websocket-star-rendezvous": "~0.2.4", diff --git a/test/files.js b/test/files.js index efee4c6b..2abcd869 100644 --- a/test/files.js +++ b/test/files.js @@ -26,7 +26,7 @@ function checkNodeTypes (daemon, file) { expect(node.links.length).to.equal(2) return Promise.all( - node.links.map(link => daemon.api.object.get(link.toJSON().multihash).then(child => { + node.links.map(link => daemon.api.object.get(link.toJSON().cid).then(child => { const childMeta = UnixFs.unmarshal(child.data) expect(childMeta.type).to.equal('raw') @@ -196,7 +196,7 @@ describe('files', function () { describe('has the same hashes for', () => { const testHashesAreEqual = (daemon, data, options) => { - return daemon.api.files.add(data, options) + return daemon.api.add(data, options) .then(files => files[0].hash) } diff --git a/test/utils/circuit.js b/test/utils/circuit.js index 36e1352c..6ec50832 100644 --- a/test/utils/circuit.js +++ b/test/utils/circuit.js @@ -98,8 +98,8 @@ exports.createGoNode = (addrs, callback) => { const data = crypto.randomBytes(128) exports.send = (nodeA, nodeB, callback) => { waterfall([ - (cb) => nodeA.files.add(data, cb), - (res, cb) => nodeB.files.cat(res[0].hash, cb), + (cb) => nodeA.add(data, cb), + (res, cb) => nodeB.cat(res[0].hash, cb), (buffer, cb) => { expect(buffer).to.deep.equal(data) cb() From 7c74643e41143c6779f043ecf9e4a87d0ee5362b Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 18 Dec 2018 17:02:49 +0000 Subject: [PATCH 3/3] fix: check for similar messages instead of identical --- test/files.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/files.js b/test/files.js index 2abcd869..0b0a12c1 100644 --- a/test/files.js +++ b/test/files.js @@ -67,11 +67,11 @@ const compare = (...ops) => { }) } -const compareErrors = (...ops) => { +const compareErrors = (expectedMessage, ...ops) => { expect(ops.length).to.be.above(1) return Promise.all( - // even if operations fail, their errors should be the same + // even if operations fail, their errors should be similar ops.map(op => op.then(() => { throw new ExpectedError('Expected operation to fail') }).catch(error => { @@ -88,9 +88,17 @@ const compareErrors = (...ops) => { .then(results => { expect(results.length).to.equal(ops.length) + // all implementations should have similar error messages + results.forEach(res => { + expect(res.message.toLowerCase()).to.contain(expectedMessage.toLowerCase()) + }) + const result = results.pop() - results.forEach(res => expect(res).to.deep.equal(result)) + // all implementations should have the same error code + results.forEach(res => { + expect(res.code).to.equal(result.code) + }) }) } @@ -138,6 +146,7 @@ describe('files', function () { } return compareErrors( + 'does not exist', readNonExistentFile(go), readNonExistentFile(js) ) @@ -149,6 +158,7 @@ describe('files', function () { } return compareErrors( + 'does not exist', readNonExistentFile(go), readNonExistentFile(js) ) @@ -171,6 +181,7 @@ describe('files', function () { const path = `/test-dir-${Math.random()}` return compareErrors( + 'already exists', go.api.files.mkdir(path).then(() => go.api.files.mkdir(path)), js.api.files.mkdir(path).then(() => js.api.files.mkdir(path)) ) @@ -189,6 +200,7 @@ describe('files', function () { const path = '/' return compareErrors( + 'already exists', go.api.files.mkdir(path).then(() => go.api.files.mkdir(path)), js.api.files.mkdir(path).then(() => js.api.files.mkdir(path)) )