Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Merged
Changes from 2 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
26 changes: 24 additions & 2 deletions js/src/files-regular/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -176,5 +176,27 @@ module.exports = (createCommon, options) => {
done()
})
})

it('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()
})
})
})
})
}