|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const expect = require('chai').expect |
| 4 | +const pull = require('pull-stream') |
| 5 | + |
| 6 | +const IPFS = require('../../src/core') |
| 7 | +const createTempRepo = require('../utils/create-repo-node.js') |
| 8 | + |
| 9 | +describe('files dir', () => { |
| 10 | + |
| 11 | + const files = [] |
| 12 | + for(let i = 0; i < 1005; i++) { |
| 13 | + files.push({ |
| 14 | + path: 'test-folder/' + i, |
| 15 | + content: new Buffer('some content ' + i) |
| 16 | + }) |
| 17 | + } |
| 18 | + |
| 19 | + describe('without sharding', () => { |
| 20 | + let ipfs |
| 21 | + |
| 22 | + before((done) => { |
| 23 | + ipfs = new IPFS({ |
| 24 | + repo: createTempRepo(), |
| 25 | + config: { |
| 26 | + Bootstrap: [] |
| 27 | + } |
| 28 | + }) |
| 29 | + ipfs.once('start', done) |
| 30 | + }) |
| 31 | + |
| 32 | + after((done) => { |
| 33 | + ipfs.stop(done) |
| 34 | + }) |
| 35 | + |
| 36 | + it('should be able to add dir without sharding', (done) => { |
| 37 | + pull( |
| 38 | + pull.values(files), |
| 39 | + ipfs.files.createAddPullStream(), |
| 40 | + pull.collect((err, results) => { |
| 41 | + const last = results[results.length - 1] |
| 42 | + expect(last.path).to.be.eql('test-folder') |
| 43 | + expect(last.hash).to.be.eql('QmWWM8ZV6GPhqJ46WtKcUaBPNHN5yQaFsKDSQ1RE73w94Q') |
| 44 | + done() |
| 45 | + }) |
| 46 | + ) |
| 47 | + |
| 48 | + after((done) => { |
| 49 | + ipfs.stop(() => done()) // ignore stop errors |
| 50 | + }) |
| 51 | + |
| 52 | + }).timeout(4000) |
| 53 | + }) |
| 54 | + |
| 55 | + describe('with sharding', () => { |
| 56 | + let ipfs |
| 57 | + |
| 58 | + before((done) => { |
| 59 | + ipfs = new IPFS({ |
| 60 | + repo: createTempRepo(), |
| 61 | + config: { |
| 62 | + Bootstrap: [] |
| 63 | + }, |
| 64 | + EXPERIMENTAL: { |
| 65 | + sharding: true |
| 66 | + } |
| 67 | + }) |
| 68 | + ipfs.once('start', done) |
| 69 | + }) |
| 70 | + |
| 71 | + after((done) => { |
| 72 | + ipfs.stop(() => done()) // ignore stop errors |
| 73 | + }) |
| 74 | + |
| 75 | + it('should be able to add dir with sharding', (done) => { |
| 76 | + pull( |
| 77 | + pull.values(files), |
| 78 | + ipfs.files.createAddPullStream(), |
| 79 | + pull.collect((err, results) => { |
| 80 | + const last = results[results.length - 1] |
| 81 | + expect(last.path).to.be.eql('test-folder') |
| 82 | + expect(last.hash).to.be.eql('QmZjYC1kWrLmiRYbEmGSo2PEpMixzT2k2xoCKSBzt8KDcy') |
| 83 | + done() |
| 84 | + }) |
| 85 | + ) |
| 86 | + |
| 87 | + }).timeout(4000) |
| 88 | + }) |
| 89 | +}) |
0 commit comments