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

Commit 7517949

Browse files
author
Alan Shaw
committed
fix: move chunker utils tests
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 54004b5 commit 7517949

File tree

3 files changed

+79
-67
lines changed

3 files changed

+79
-67
lines changed

test/core/files-regular-utils.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
})

test/core/node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
require('./circuit-relay')
4+
require('./files-regular-utils')
45
require('./name')
56
require('./key-exchange')
67
require('./pin')

test/core/utils.js

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -185,71 +185,4 @@ describe('utils', () => {
185185
})
186186
})
187187
})
188-
189-
describe('parseChunkerString', () => {
190-
it('handles an empty string', () => {
191-
const options = utils.parseChunkerString('')
192-
expect(options).to.have.property('chunker').to.equal('fixed')
193-
})
194-
195-
it('handles a null chunker string', () => {
196-
const options = utils.parseChunkerString(null)
197-
expect(options).to.have.property('chunker').to.equal('fixed')
198-
})
199-
200-
it('parses a fixed size string', () => {
201-
const options = utils.parseChunkerString('size-512')
202-
expect(options).to.have.property('chunker').to.equal('fixed')
203-
expect(options)
204-
.to.have.property('chunkerOptions')
205-
.to.have.property('maxChunkSize')
206-
.to.equal(512)
207-
})
208-
209-
it('parses a rabin string without size', () => {
210-
const options = utils.parseChunkerString('rabin')
211-
expect(options).to.have.property('chunker').to.equal('rabin')
212-
expect(options)
213-
.to.have.property('chunkerOptions')
214-
.to.have.property('avgChunkSize')
215-
})
216-
217-
it('parses a rabin string with only avg size', () => {
218-
const options = utils.parseChunkerString('rabin-512')
219-
expect(options).to.have.property('chunker').to.equal('rabin')
220-
expect(options)
221-
.to.have.property('chunkerOptions')
222-
.to.have.property('avgChunkSize')
223-
.to.equal(512)
224-
})
225-
226-
it('parses a rabin string with min, avg, and max', () => {
227-
const options = utils.parseChunkerString('rabin-42-92-184')
228-
expect(options).to.have.property('chunker').to.equal('rabin')
229-
expect(options).to.have.property('chunkerOptions')
230-
expect(options.chunkerOptions).to.have.property('minChunkSize').to.equal(42)
231-
expect(options.chunkerOptions).to.have.property('avgChunkSize').to.equal(92)
232-
expect(options.chunkerOptions).to.have.property('maxChunkSize').to.equal(184)
233-
})
234-
235-
it('throws an error for unsupported chunker type', () => {
236-
const fn = () => utils.parseChunkerString('fake-512')
237-
expect(fn).to.throw(Error)
238-
})
239-
240-
it('throws an error for incorrect format string', () => {
241-
const fn = () => utils.parseChunkerString('fixed-abc')
242-
expect(fn).to.throw(Error)
243-
})
244-
245-
it('throws an error for incorrect rabin format string', () => {
246-
let fn = () => utils.parseChunkerString('rabin-1-2-3-4')
247-
expect(fn).to.throw(Error)
248-
})
249-
250-
it('throws an error for non integer rabin parameters', () => {
251-
const fn = () => utils.parseChunkerString('rabin-abc')
252-
expect(fn).to.throw(Error)
253-
})
254-
})
255188
})

0 commit comments

Comments
 (0)