|
| 1 | +/* eslint max-nested-callbacks: ["error", 8] */ |
| 2 | +/* eslint-env mocha */ |
| 3 | +'use strict' |
| 4 | + |
| 5 | +const chai = require('chai') |
| 6 | +const dirtyChai = require('dirty-chai') |
| 7 | +const expect = chai.expect |
| 8 | +chai.use(dirtyChai) |
| 9 | +const utils = require('../../src/core/components/files-regular/utils') |
| 10 | + |
| 11 | +describe('files-regular/utils', () => { |
| 12 | + describe('parseChunkerString', () => { |
| 13 | + it('handles an empty string', () => { |
| 14 | + const options = utils.parseChunkerString('') |
| 15 | + expect(options).to.have.property('chunker').to.equal('fixed') |
| 16 | + }) |
| 17 | + |
| 18 | + it('handles a null chunker string', () => { |
| 19 | + const options = utils.parseChunkerString(null) |
| 20 | + expect(options).to.have.property('chunker').to.equal('fixed') |
| 21 | + }) |
| 22 | + |
| 23 | + it('parses a fixed size string', () => { |
| 24 | + const options = utils.parseChunkerString('size-512') |
| 25 | + expect(options).to.have.property('chunker').to.equal('fixed') |
| 26 | + expect(options) |
| 27 | + .to.have.property('chunkerOptions') |
| 28 | + .to.have.property('maxChunkSize') |
| 29 | + .to.equal(512) |
| 30 | + }) |
| 31 | + |
| 32 | + it('parses a rabin string without size', () => { |
| 33 | + const options = utils.parseChunkerString('rabin') |
| 34 | + expect(options).to.have.property('chunker').to.equal('rabin') |
| 35 | + expect(options) |
| 36 | + .to.have.property('chunkerOptions') |
| 37 | + .to.have.property('avgChunkSize') |
| 38 | + }) |
| 39 | + |
| 40 | + it('parses a rabin string with only avg size', () => { |
| 41 | + const options = utils.parseChunkerString('rabin-512') |
| 42 | + expect(options).to.have.property('chunker').to.equal('rabin') |
| 43 | + expect(options) |
| 44 | + .to.have.property('chunkerOptions') |
| 45 | + .to.have.property('avgChunkSize') |
| 46 | + .to.equal(512) |
| 47 | + }) |
| 48 | + |
| 49 | + it('parses a rabin string with min, avg, and max', () => { |
| 50 | + const options = utils.parseChunkerString('rabin-42-92-184') |
| 51 | + expect(options).to.have.property('chunker').to.equal('rabin') |
| 52 | + expect(options).to.have.property('chunkerOptions') |
| 53 | + expect(options.chunkerOptions).to.have.property('minChunkSize').to.equal(42) |
| 54 | + expect(options.chunkerOptions).to.have.property('avgChunkSize').to.equal(92) |
| 55 | + expect(options.chunkerOptions).to.have.property('maxChunkSize').to.equal(184) |
| 56 | + }) |
| 57 | + |
| 58 | + it('throws an error for unsupported chunker type', () => { |
| 59 | + const fn = () => utils.parseChunkerString('fake-512') |
| 60 | + expect(fn).to.throw(Error) |
| 61 | + }) |
| 62 | + |
| 63 | + it('throws an error for incorrect format string', () => { |
| 64 | + const fn = () => utils.parseChunkerString('fixed-abc') |
| 65 | + expect(fn).to.throw(Error) |
| 66 | + }) |
| 67 | + |
| 68 | + it('throws an error for incorrect rabin format string', () => { |
| 69 | + let fn = () => utils.parseChunkerString('rabin-1-2-3-4') |
| 70 | + expect(fn).to.throw(Error) |
| 71 | + }) |
| 72 | + |
| 73 | + it('throws an error for non integer rabin parameters', () => { |
| 74 | + const fn = () => utils.parseChunkerString('rabin-abc') |
| 75 | + expect(fn).to.throw(Error) |
| 76 | + }) |
| 77 | + }) |
| 78 | +}) |
0 commit comments