File tree Expand file tree Collapse file tree 3 files changed +50
-8
lines changed Expand file tree Collapse file tree 3 files changed +50
-8
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,7 @@ set -euo pipefail
7
7
# or 500M, or a percentage like 5%
8
8
# min inodes must be a number, default to 250,000
9
9
10
- # Converts human-readable units like 1.43K and 120.3M to bytes
11
- dehumanize () {
12
- awk ' /[0-9][bB]?$/ {printf "%u\n", $1*1024}
13
- /[tT][bB]?$/ {printf "%u\n", $1*(1024*1024*1024)}
14
- /[gG][bB]?$/ {printf "%u\n", $1*(1024*1024)}
15
- /[mM][bB]?$/ {printf "%u\n", $1*(1024)}
16
- /[kK][bB]?$/ {printf "%u\n", $1*1}' <<< " $1"
17
- }
10
+ . " $( dirname " $0 " ) " /dehumanize.sh
18
11
19
12
min_available=${1:- 5G}
20
13
docker_dir=" /var/lib/docker/"
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ set -o pipefail
3
+
4
+ . " $( dirname " $0 " ) " /dehumanize.sh
5
+
6
+ test_without_unit (){
7
+ assertEquals 45 $( dehumanize 45)
8
+ }
9
+
10
+ test_bytes (){
11
+ assertEquals 45 $( dehumanize 45b)
12
+ assertEquals 45 $( dehumanize 45B)
13
+ }
14
+
15
+ test_kilobytes (){
16
+ assertEquals 46080 $( dehumanize 45kb)
17
+ assertEquals 46080 $( dehumanize 45KB)
18
+ }
19
+
20
+ test_megabytes (){
21
+ assertEquals 47185920 $( dehumanize 45mb)
22
+ assertEquals 47185920 $( dehumanize 45MB)
23
+ }
24
+
25
+ test_gigabytes (){
26
+ assertEquals 48318382080 $( dehumanize 45gb)
27
+ assertEquals 48318382080 $( dehumanize 45GB)
28
+ }
29
+
30
+ test_terabytes (){
31
+ assertEquals 49478023249920 $( dehumanize 45tb)
32
+ assertEquals 49478023249920 $( dehumanize 45TB)
33
+ }
34
+
35
+ test_using_decimals (){
36
+ assertEquals 1610612736 $( dehumanize 1.5gb)
37
+ }
38
+
39
+ . shunit2
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # Converts human-readable units like 1.43K and 120.3M to bytes
4
+ dehumanize () {
5
+ awk ' /[0-9][bB]?$/ {printf "%u\n", $1*1}
6
+ /[tT][bB]?$/ {printf "%u\n", $1*(1024*1024*1024*1024)}
7
+ /[gG][bB]?$/ {printf "%u\n", $1*(1024*1024*1024)}
8
+ /[mM][bB]?$/ {printf "%u\n", $1*(1024*1024)}
9
+ /[kK][bB]?$/ {printf "%u\n", $1*1024}' <<< " $1"
10
+ }
You can’t perform that action at this time.
0 commit comments