Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

test: add test for ls by IPFS path #420

Merged
merged 3 commits into from
Dec 14, 2018
Merged
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
27 changes: 25 additions & 2 deletions js/src/files-regular/ls.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 6] */
'use strict'

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 +109,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 +136,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 +177,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()
})
})
})
})
}