|
1 | 1 | /* eslint-env mocha */
|
| 2 | +/* eslint max-nested-callbacks: ["error", 6] */ |
2 | 3 | 'use strict'
|
3 | 4 |
|
4 | 5 | const { fixtures } = require('./utils')
|
5 | 6 | const { getDescribe, getIt, expect } = require('../utils/mocha')
|
6 | 7 | const CID = require('cids')
|
7 | 8 |
|
| 9 | +const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` |
| 10 | + |
8 | 11 | module.exports = (createCommon, options) => {
|
9 | 12 | const describe = getDescribe(options)
|
10 | 13 | const it = getIt(options)
|
@@ -106,7 +109,6 @@ module.exports = (createCommon, options) => {
|
106 | 109 | })
|
107 | 110 |
|
108 | 111 | it('should ls files added as CIDv0 with a CIDv1', done => {
|
109 |
| - const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` |
110 | 112 | const dir = randomName('DIR')
|
111 | 113 |
|
112 | 114 | const input = [
|
@@ -134,7 +136,6 @@ module.exports = (createCommon, options) => {
|
134 | 136 | })
|
135 | 137 |
|
136 | 138 | it('should ls files added as CIDv1 with a CIDv0', done => {
|
137 |
| - const randomName = prefix => `${prefix}${Math.round(Math.random() * 1000)}` |
138 | 139 | const dir = randomName('DIR')
|
139 | 140 |
|
140 | 141 | const input = [
|
@@ -176,5 +177,27 @@ module.exports = (createCommon, options) => {
|
176 | 177 | done()
|
177 | 178 | })
|
178 | 179 | })
|
| 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 | + }) |
179 | 202 | })
|
180 | 203 | }
|
0 commit comments