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

Commit 9b2fb0f

Browse files
committed
fix directory test
1 parent abb7c01 commit 9b2fb0f

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/files.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const through = require('through2')
1919
const bl = require('bl')
2020

2121
module.exports = (common) => {
22-
describe('.files', function () {
22+
describe.only('.files', function () {
2323
this.timeout(5 * 1000)
2424

2525
let ipfs
@@ -711,12 +711,41 @@ module.exports = (common) => {
711711
})
712712

713713
describe('.ls', () => {
714-
it('with a base58 encoded string', (done) => {
715-
const hash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
716-
ipfs.ls(hash, (err, files) => {
714+
before((done) => {
715+
const content = (name) => ({
716+
path: `test-folder/${name}`,
717+
content: directory.files[name]
718+
})
719+
720+
const emptyDir = (name) => ({ path: `test-folder/${name}` })
721+
722+
const dirs = [
723+
content('pp.txt'),
724+
content('holmes.txt'),
725+
content('jungle.txt'),
726+
content('alice.txt'),
727+
emptyDir('empty-folder'),
728+
content('files/hello.txt'),
729+
content('files/ipfs.txt'),
730+
emptyDir('files/empty')
731+
]
732+
733+
ipfs.files.add(dirs, (err, res) => {
717734
expect(err).to.not.exist()
718-
files.forEach((file) => delete file.content)
719-
expect(files).to.deep.equal([
735+
const root = res[res.length - 1]
736+
737+
expect(root.path).to.equal('test-folder')
738+
expect(root.hash).to.equal(directory.cid)
739+
done()
740+
})
741+
})
742+
743+
it('with a base58 encoded CID', (done) => {
744+
const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
745+
ipfs.ls(cid, (err, files) => {
746+
expect(err).to.not.exist()
747+
748+
expect(files).to.eql([
720749
{ depth: 1,
721750
name: 'alice.txt',
722751
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
@@ -752,7 +781,8 @@ module.exports = (common) => {
752781
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
753782
size: 4551,
754783
hash: 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn',
755-
type: 'file' } ])
784+
type: 'file' }
785+
])
756786
done()
757787
})
758788
})

0 commit comments

Comments
 (0)