aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/helpers
diff options
context:
space:
mode:
authorBRAINS YUM <43896676+McFlat@users.noreply.github.com>2018-10-13 01:43:55 -0500
committerChocobozzz <me@florianbigard.com>2018-10-13 08:43:55 +0200
commit0e5ff97f6fdf9a4cebe5a15f5a390380465803ad (patch)
treee3f69adb2b8a910ef750b44972ea59944aa9ca7c /server/tests/helpers
parent6e5a785b20230ff5457632361a893d814b53c95e (diff)
downloadPeerTube-0e5ff97f6fdf9a4cebe5a15f5a390380465803ad.tar.gz
PeerTube-0e5ff97f6fdf9a4cebe5a15f5a390380465803ad.tar.zst
PeerTube-0e5ff97f6fdf9a4cebe5a15f5a390380465803ad.zip
add parseBytes utility function and tests (#1239)
* add parseBytes utility function and tests make it parse TB MB fix parseBytes; * 1024 test bytes too, and make parseByte to parse quotas add test in travis.sh in misc * fix parseBytes and test to pass linting
Diffstat (limited to 'server/tests/helpers')
-rw-r--r--server/tests/helpers/core-utils.ts48
-rw-r--r--server/tests/helpers/index.ts1
2 files changed, 49 insertions, 0 deletions
diff --git a/server/tests/helpers/core-utils.ts b/server/tests/helpers/core-utils.ts
new file mode 100644
index 000000000..a6d829a9f
--- /dev/null
+++ b/server/tests/helpers/core-utils.ts
@@ -0,0 +1,48 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import {
6 parseBytes
7} from '../../helpers/core-utils'
8
9const expect = chai.expect
10
11describe('Parse Bytes', function () {
12 it('Should pass when given valid value', async function () {
13 // just return it
14 expect(parseBytes(1024)).to.be.eq(1024)
15 expect(parseBytes(1048576)).to.be.eq(1048576)
16 expect(parseBytes('1024')).to.be.eq(1024)
17 expect(parseBytes('1048576')).to.be.eq(1048576)
18
19 // sizes
20 expect(parseBytes('1B')).to.be.eq(1024)
21 expect(parseBytes('1MB')).to.be.eq(1048576)
22 expect(parseBytes('1GB')).to.be.eq(1073741824)
23 expect(parseBytes('1TB')).to.be.eq(1099511627776)
24
25 expect(parseBytes('5GB')).to.be.eq(5368709120)
26 expect(parseBytes('5TB')).to.be.eq(5497558138880)
27
28 expect(parseBytes('1024B')).to.be.eq(1048576)
29 expect(parseBytes('1024MB')).to.be.eq(1073741824)
30 expect(parseBytes('1024GB')).to.be.eq(1099511627776)
31 expect(parseBytes('1024TB')).to.be.eq(1125899906842624)
32
33 // with whitespace
34 expect(parseBytes('1 GB')).to.be.eq(1073741824)
35 expect(parseBytes('1\tGB')).to.be.eq(1073741824)
36
37 // sum value
38 expect(parseBytes('1TB 1024MB')).to.be.eq(1100585369600)
39 expect(parseBytes('4GB 1024MB')).to.be.eq(5368709120)
40 expect(parseBytes('4TB 1024GB')).to.be.eq(5497558138880)
41 expect(parseBytes('4TB 1024GB 0MB')).to.be.eq(5497558138880)
42 expect(parseBytes('1024TB 1024GB 1024MB')).to.be.eq(1127000492212224)
43 })
44
45 it('Should be invalid when given invalid value', async function () {
46 expect(parseBytes('6GB 1GB')).to.be.eq(6)
47 })
48})
diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts
new file mode 100644
index 000000000..40c7dc70e
--- /dev/null
+++ b/server/tests/helpers/index.ts
@@ -0,0 +1 @@
import './core-utils'