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

Commit

Permalink
add remaining tests for .ls .lsReadableStream and .lsPullStream
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Nov 14, 2017
1 parent b3520cc commit dd92252
Showing 1 changed file with 161 additions and 0 deletions.
161 changes: 161 additions & 0 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,5 +739,166 @@ module.exports = (common) => {
})
})
})

describe('.lsReadableStream', () => {
before((done) => {
const content = (name) => ({
path: `test-folder/${name}`,
content: directory.files[name]
})

const emptyDir = (name) => ({ path: `test-folder/${name}` })

const dirs = [
content('pp.txt'),
content('holmes.txt'),
content('jungle.txt'),
content('alice.txt'),
emptyDir('empty-folder'),
content('files/hello.txt'),
content('files/ipfs.txt'),
emptyDir('files/empty')
]

ipfs.files.add(dirs, (err, res) => {
expect(err).to.not.exist()
const root = res[res.length - 1]

expect(root.path).to.equal('test-folder')
expect(root.hash).to.equal(directory.cid)
done()
})
})

it('with a base58 encoded CID', (done) => {
const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
const stream = ipfs.lsReadableStream(cid)

stream.pipe(concat((files) => {
expect(files).to.eql([
{ depth: 1,
name: 'alice.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
size: 11696,
hash: 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi',
type: 'file' },
{ depth: 1,
name: 'empty-folder',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
size: 4,
hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn',
type: 'dir' },
{ depth: 1,
name: 'files',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
size: 183,
hash: 'QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74',
type: 'dir' },
{ depth: 1,
name: 'holmes.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
size: 582072,
hash: 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr',
type: 'file' },
{ depth: 1,
name: 'jungle.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
size: 2305,
hash: 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9',
type: 'file' },
{ depth: 1,
name: 'pp.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
size: 4551,
hash: 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn',
type: 'file' }
])
done()
}))
})
})

describe('.lsPullStream', () => {
before((done) => {
const content = (name) => ({
path: `test-folder/${name}`,
content: directory.files[name]
})

const emptyDir = (name) => ({ path: `test-folder/${name}` })

const dirs = [
content('pp.txt'),
content('holmes.txt'),
content('jungle.txt'),
content('alice.txt'),
emptyDir('empty-folder'),
content('files/hello.txt'),
content('files/ipfs.txt'),
emptyDir('files/empty')
]

ipfs.files.add(dirs, (err, res) => {
expect(err).to.not.exist()
const root = res[res.length - 1]

expect(root.path).to.equal('test-folder')
expect(root.hash).to.equal(directory.cid)
done()
})
})

it('with a base58 encoded CID', (done) => {
const cid = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
const stream = ipfs.lsPullStream(cid)

pull(
stream,
pull.collect((err, files) => {
expect(err).to.not.exist()

expect(files).to.eql([
{ depth: 1,
name: 'alice.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/alice.txt',
size: 11696,
hash: 'QmZyUEQVuRK3XV7L9Dk26pg6RVSgaYkiSTEdnT2kZZdwoi',
type: 'file' },
{ depth: 1,
name: 'empty-folder',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/empty-folder',
size: 4,
hash: 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn',
type: 'dir' },
{ depth: 1,
name: 'files',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/files',
size: 183,
hash: 'QmZ25UfTqXGz9RsEJFg7HUAuBcmfx5dQZDXQd2QEZ8Kj74',
type: 'dir' },
{ depth: 1,
name: 'holmes.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/holmes.txt',
size: 582072,
hash: 'QmR4nFjTu18TyANgC65ArNWp5Yaab1gPzQ4D8zp7Kx3vhr',
type: 'file' },
{ depth: 1,
name: 'jungle.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/jungle.txt',
size: 2305,
hash: 'QmT6orWioMiSqXXPGsUi71CKRRUmJ8YkuueV2DPV34E9y9',
type: 'file' },
{ depth: 1,
name: 'pp.txt',
path: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP/pp.txt',
size: 4551,
hash: 'QmVwdDCY4SPGVFnNCiZnX5CtzwWDn6kAM98JXzKxE3kCmn',
type: 'file' }
])
done()
})
)
})
})
})
}

0 comments on commit dd92252

Please sign in to comment.