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

Test cidVersion option #186

Merged
merged 1 commit into from
Sep 8, 2017
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
47 changes: 47 additions & 0 deletions test/test-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const mh = require('multihashes')
const CID = require('cids')
const IPLDResolver = require('ipld-resolver')
const loadFixture = require('aegir/fixtures')
const each = require('async/each')

function stringifyMh (files) {
return files.map((file) => {
Expand Down Expand Up @@ -466,6 +467,52 @@ module.exports = (repo) => {
})
)
})

it('will import files with CID version 1', (done) => {
const createInputFile = (path, size) => {
const name = String(Math.random() + Date.now())
path = path[path.length - 1] === '/' ? path : path + '/'
return {
path: path + name + '.txt',
content: Buffer.alloc(262144 + 5).fill(1)
}
}

const options = {
cidVersion: 1,
// Ensures we use DirSharded for the data below
shardSplitThreshold: 3
}

const onCollected = (err, files) => {
if (err) return done(err)

const file = files[0]
expect(file).to.exist()

each(files, (file, cb) => {
const cid = new CID(file.multihash).toV1()
ipldResolver.get(cid, cb)
}, done)
}

pull(
pull.values([
createInputFile('/foo', 10),
createInputFile('/foo', 60),
createInputFile('/foo/bar', 78),
createInputFile('/foo/baz', 200),
// Bigger than maxChunkSize
createInputFile('/foo', 262144 + 45),
createInputFile('/foo/bar', 262144 + 134),
createInputFile('/foo/bar', 262144 + 79),
createInputFile('/foo/bar', 262144 + 876),
createInputFile('/foo/bar', 262144 + 21)
]),
importer(ipldResolver, options),
pull.collect(onCollected)
)
})
})
})
}