Skip to content

Commit 2c3317d

Browse files
committed
refactor
1 parent da0eac0 commit 2c3317d

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

tests-ng/test-du.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,24 @@ clear_on_exit "${tmpd}"
2222

2323
catalog="${tmpd}/catalog"
2424
out="${tmpd}/output.txt"
25+
path="${cur}/../"
2526

2627
# index
27-
"${bin}" index -a -C -c "${catalog}" "${cur}/../" gocatcli
28+
"${bin}" index -a -C -c "${catalog}" "${path}" gocatcli
2829
[ ! -e "${catalog}" ] && echo "catalog not created" && exit 1
2930

3031
echo ">>> test du raw <<<"
3132
"${bin}" --debug du -S -c "${catalog}" | sed -e 's/\x1b\[[0-9;]*m//g' > "${out}"
3233

3334
# shellcheck disable=SC2126
34-
expected=$(find "${cur}/../" -type d | grep -v '^.$' | wc -l)
35+
expected=$(find "${path}" -type d | grep -v '^.$' | wc -l)
3536
cnt=$(wc -l "${out}" | awk '{print $1}')
3637
[ "${cnt}" != "${expected}" ] && echo "expecting ${expected} lines (${cnt})" && exit 1
3738

38-
# bin size
39-
echo ">>> test du bin size raw <<<"
40-
#expected=$(du -c --block=1 --apparent-size "${cur}/../cmd/gocatcli" | tail -1 | awk '{print $1}')
41-
expected=$("${cur}/pdu.py" "${cur}/../cmd/gocatcli" | tail -1 | awk '{print $1}')
42-
size=$(grep '^.* *gocatcli/cmd/gocatcli$' "${out}" | awk '{print $1}')
43-
echo "size:${size} VS exp:${expected}"
44-
[ "${expected}" != "${size}" ] && (echo "bad bin size" && exit 1)
45-
4639
# total size
4740
echo ">>> test du total size raw <<<"
4841
#expected=$(du -c --block=1 --apparent-size "${cur}/../" | tail -1 | awk '{print $1}')
49-
expected=$("${cur}/pdu.py" "${cur}/../" | tail -1 | awk '{print $1}')
42+
expected=$("${cur}/pdu.py" "${path}" | tail -1 | awk '{print $1}')
5043
#cat_file "${out}"
5144
size=$(tail -1 "${out}" | awk '{print $1}')
5245
echo "size:${size} VS exp:${expected}"
@@ -55,7 +48,7 @@ echo "size:${size} VS exp:${expected}"
5548
echo ">>> test du human size <<<"
5649
"${bin}" --debug du -c "${catalog}" | sed -e 's/\x1b\[[0-9;]*m//g' > "${out}"
5750
# shellcheck disable=SC2126
58-
expected=$(find "${cur}/../" -type d | grep -v '^.$' | wc -l)
51+
expected=$(find "${path}" -type d | grep -v '^.$' | wc -l)
5952
cnt=$(wc -l "${out}" | awk '{print $1}')
6053
[ "${cnt}" != "${expected}" ] && echo "expecting ${expected} lines (${cnt})" && exit 1
6154

@@ -64,11 +57,20 @@ echo ">>> test du total size human <<<"
6457
#expected=$(du -c --block=1 --apparent-size "${cur}/../" | tail -1 | awk '{print $1}' | sed 's/M//g')
6558
# for some reason "du -h" uses 1000 with above options instead of 1024
6659
#expected=$(awk 'BEGIN {printf "%.0f",'"${expected}"'/1024/1024}')
67-
expected=$("${cur}/pdu.py" --human "${cur}/../" | tail -1 | awk '{print $1}' | sed 's/M//g')
60+
"${cur}/pdu.py" --human "${path}"
61+
expected=$("${cur}/pdu.py" --human "${path}" | tail -1 | awk '{print $1}' | sed -e 's/M//g' -e 's/K//g')
6862
cat_file "${out}"
69-
size=$(tail -1 "${out}" | awk '{print $1}' | sed 's/MiB//g' | sed 's/MB//g')
63+
size=$(tail -1 "${out}" | awk '{print $1}' | sed -e 's/MiB//g' -e 's/MB//g' -e 's/kB//g' -e 's/\..*$//g')
7064
echo "size:${size} VS exp:${expected}"
7165
[ "${expected}" != "${size}" ] && (echo "bad total human size" && exit 1)
7266

67+
# bin size
68+
echo ">>> test du bin size raw <<<"
69+
#expected=$(du -c --block=1 --apparent-size "${path}" | tail -1 | awk '{print $1}')
70+
expected=$("${cur}/pdu.py" "${cur}/../cmd/gocatcli" | tail -1 | awk '{print $1}')
71+
size=$(grep '^.* *gocatcli/cmd/gocatcli$' "${out}" | awk '{print $1}')
72+
echo "size:${size} VS exp:${expected}"
73+
[ "${expected}" != "${size}" ] && (echo "bad bin size" && exit 1)
74+
7375
echo "test $(basename "${0}") OK!"
7476
exit 0

0 commit comments

Comments
 (0)