From 7d9d9751316b898fabe5a6fc65ffae3bbe3027d9 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 14 Dec 2018 16:52:49 +0000 Subject: [PATCH 1/3] test: add test for ls by IPFS path License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/ls.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/js/src/files-regular/ls.js b/js/src/files-regular/ls.js index 286d02bbe..f07ab27f3 100644 --- a/js/src/files-regular/ls.js +++ b/js/src/files-regular/ls.js @@ -5,6 +5,8 @@ const { fixtures } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const CID = require('cids') +const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` + module.exports = (createCommon, options) => { const describe = getDescribe(options) const it = getIt(options) @@ -106,7 +108,6 @@ module.exports = (createCommon, options) => { }) it('should ls files added as CIDv0 with a CIDv1', done => { - const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` const dir = randomName('DIR') const input = [ @@ -134,7 +135,6 @@ module.exports = (createCommon, options) => { }) it('should ls files added as CIDv1 with a CIDv0', done => { - const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` const dir = randomName('DIR') const input = [ @@ -176,5 +176,27 @@ module.exports = (createCommon, options) => { done() }) }) + + it.only('should ls files by path', done => { + const dir = randomName('DIR') + + const input = [ + { path: `${dir}/${randomName('F0')}`, content: Buffer.from(randomName('D0')) }, + { path: `${dir}/${randomName('F1')}`, content: Buffer.from(randomName('D1')) } + ] + + ipfs.add(input, (err, res) => { + expect(err).to.not.exist() + + ipfs.ls(`/ipfs/${res[res.length - 1].hash}`, (err, output) => { + expect(err).to.not.exist() + expect(output.length).to.equal(input.length) + output.forEach(({ hash }) => { + expect(res.find(file => file.hash === hash)).to.exist() + }) + done() + }) + }) + }) }) } From ed29872bc6c61194801589804626a83e096ed641 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 14 Dec 2018 16:53:41 +0000 Subject: [PATCH 2/3] fix: remove .only License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/ls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/files-regular/ls.js b/js/src/files-regular/ls.js index f07ab27f3..1bee2e4a6 100644 --- a/js/src/files-regular/ls.js +++ b/js/src/files-regular/ls.js @@ -177,7 +177,7 @@ module.exports = (createCommon, options) => { }) }) - it.only('should ls files by path', done => { + it('should ls files by path', done => { const dir = randomName('DIR') const input = [ From 743c76aa19caa95dff89114fb72bfb18cf3a51ee Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 14 Dec 2018 17:20:27 +0000 Subject: [PATCH 3/3] chore: apprease linter License: MIT Signed-off-by: Alan Shaw --- js/src/files-regular/ls.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/files-regular/ls.js b/js/src/files-regular/ls.js index 1bee2e4a6..bab3544cc 100644 --- a/js/src/files-regular/ls.js +++ b/js/src/files-regular/ls.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 6] */ 'use strict' const { fixtures } = require('./utils')