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

Commit e723586

Browse files
committed
testing import and export using various builder strategies
1 parent 8ac163c commit e723586

File tree

4 files changed

+90
-24
lines changed

4 files changed

+90
-24
lines changed

test/browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ describe('IPFS data importing tests on the Browser', function () {
5757
require('./test-fixed-size-chunker')
5858
require('./test-exporter')(repo)
5959
require('./test-importer')(repo)
60+
require('./test-import-export')(repo)
6061
})

test/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ describe('IPFS UnixFS Engine', () => {
4242
require('./test-fixed-size-chunker')
4343
require('./test-exporter')(repo)
4444
require('./test-importer')(repo)
45+
require('./test-import-export')(repo)
4546
})

test/test-exporter.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,6 @@ module.exports = (repo) => {
2525
ipldResolver = new IPLDResolver(bs)
2626
})
2727

28-
it('import and export', (done) => {
29-
pull(
30-
pull.values([{
31-
path: '1.2MiB.txt',
32-
content: pull.values([
33-
bigFile,
34-
Buffer('hello world')
35-
])
36-
}]),
37-
unixFSEngine.importer(ipldResolver),
38-
pull.map((file) => {
39-
expect(file.path).to.be.eql('1.2MiB.txt')
40-
41-
return exporter(file.multihash, ipldResolver)
42-
}),
43-
pull.flatten(),
44-
pull.collect((err, files) => {
45-
expect(err).to.not.exist
46-
expect(files[0].size).to.be.eql(bigFile.length + 11)
47-
fileEql(files[0], Buffer.concat([bigFile, Buffer('hello world')]), done)
48-
})
49-
)
50-
})
51-
5228
it('ensure hash inputs are sanitized', (done) => {
5329
const hash = 'QmQmZQxSKQppbsWfVzBvg59Cn3DKtsNVQ94bjAxg2h3Lb8'
5430
const mhBuf = new Buffer(bs58.decode(hash))

test/test-import-export.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const expect = require('chai').expect
5+
const BlockService = require('ipfs-block-service')
6+
const IPLDResolver = require('ipld-resolver')
7+
const pull = require('pull-stream')
8+
const loadFixture = require('aegir/fixtures')
9+
10+
const unixFSEngine = require('./../')
11+
const exporter = unixFSEngine.exporter
12+
13+
const bigFile = loadFixture(__dirname, 'fixtures/1.2MiB.txt')
14+
15+
const strategies = [
16+
'flat',
17+
'balanced',
18+
'trickle'
19+
]
20+
21+
module.exports = (repo) => {
22+
strategies.forEach((strategy) => {
23+
const importerOptions = {
24+
strategy: strategy,
25+
maxChildrenPerNode: 10,
26+
layerRepeat: 2,
27+
chunkerOptions: {
28+
maxChunkSize: 1024
29+
}
30+
}
31+
32+
describe('import export using ' + strategy + ' builder strategy', () => {
33+
let ipldResolver
34+
35+
before(() => {
36+
const bs = new BlockService(repo)
37+
ipldResolver = new IPLDResolver(bs)
38+
})
39+
40+
it('import and export', (done) => {
41+
const path = strategy + '-1.2MiB.txt'
42+
pull(
43+
pull.values([{
44+
path: path,
45+
content: pull.values([
46+
bigFile,
47+
Buffer('hello world')
48+
])
49+
}]),
50+
unixFSEngine.importer(ipldResolver, importerOptions),
51+
pull.map((file) => {
52+
expect(file.path).to.be.eql(path)
53+
54+
return exporter(file.multihash, ipldResolver)
55+
}),
56+
pull.flatten(),
57+
pull.collect((err, files) => {
58+
expect(err).to.not.exist
59+
expect(files[0].size).to.be.eql(bigFile.length + 11)
60+
fileEql(files[0], Buffer.concat([bigFile, Buffer('hello world')]), done)
61+
})
62+
)
63+
})
64+
})
65+
})
66+
}
67+
68+
function fileEql (f1, f2, done) {
69+
pull(
70+
f1.content,
71+
pull.collect((err, data) => {
72+
if (err) {
73+
return done(err)
74+
}
75+
76+
try {
77+
if (f2) {
78+
expect(Buffer.concat(data)).to.be.eql(f2)
79+
} else {
80+
expect(data).to.exist
81+
}
82+
} catch (err) {
83+
return done(err)
84+
}
85+
done()
86+
})
87+
)
88+
}

0 commit comments

Comments
 (0)