Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

fix: tests using files #48

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"form-data": "^2.3.3",
"go-ipfs-dep": "~0.4.18",
"hat": "0.0.3",
"ipfs": "~0.33.0",
"ipfs-api": "^26.1.2",
"ipfs": "ipfs/js-ipfs#master",
"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",
Expand Down
22 changes: 17 additions & 5 deletions test/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 => {
Expand All @@ -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)
})
})
}

Expand Down Expand Up @@ -138,6 +146,7 @@ describe('files', function () {
}

return compareErrors(
'does not exist',
readNonExistentFile(go),
readNonExistentFile(js)
)
Expand All @@ -149,6 +158,7 @@ describe('files', function () {
}

return compareErrors(
'does not exist',
readNonExistentFile(go),
readNonExistentFile(js)
)
Expand All @@ -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))
)
Expand All @@ -189,14 +200,15 @@ 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))
)
})

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)
}

Expand Down
4 changes: 2 additions & 2 deletions test/utils/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down