Skip to content

Commit 570aaf0

Browse files
author
Alan Shaw
authored
test: add test for ls by IPFS path (ipfs#420)
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 8b890b6 commit 570aaf0

File tree

1 file changed

+25
-2
lines changed
  • js/src/files-regular

1 file changed

+25
-2
lines changed

js/src/files-regular/ls.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/* eslint-env mocha */
2+
/* eslint max-nested-callbacks: ["error", 6] */
23
'use strict'
34

45
const { fixtures } = require('./utils')
56
const { getDescribe, getIt, expect } = require('../utils/mocha')
67
const CID = require('cids')
78

9+
const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}`
10+
811
module.exports = (createCommon, options) => {
912
const describe = getDescribe(options)
1013
const it = getIt(options)
@@ -106,7 +109,6 @@ module.exports = (createCommon, options) => {
106109
})
107110

108111
it('should ls files added as CIDv0 with a CIDv1', done => {
109-
const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}`
110112
const dir = randomName('DIR')
111113

112114
const input = [
@@ -134,7 +136,6 @@ module.exports = (createCommon, options) => {
134136
})
135137

136138
it('should ls files added as CIDv1 with a CIDv0', done => {
137-
const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}`
138139
const dir = randomName('DIR')
139140

140141
const input = [
@@ -176,5 +177,27 @@ module.exports = (createCommon, options) => {
176177
done()
177178
})
178179
})
180+
181+
it('should ls files by path', done => {
182+
const dir = randomName('DIR')
183+
184+
const input = [
185+
{ path: `${dir}/${randomName('F0')}`, content: Buffer.from(randomName('D0')) },
186+
{ path: `${dir}/${randomName('F1')}`, content: Buffer.from(randomName('D1')) }
187+
]
188+
189+
ipfs.add(input, (err, res) => {
190+
expect(err).to.not.exist()
191+
192+
ipfs.ls(`/ipfs/${res[res.length - 1].hash}`, (err, output) => {
193+
expect(err).to.not.exist()
194+
expect(output.length).to.equal(input.length)
195+
output.forEach(({ hash }) => {
196+
expect(res.find(file => file.hash === hash)).to.exist()
197+
})
198+
done()
199+
})
200+
})
201+
})
179202
})
180203
}

0 commit comments

Comments
 (0)