add correct test for 1515
When checking to see if GC fully reverses an `ipfs add`, we should check the size of the actual files, not the directory sizes. A bunch of empty directories won't use *that* much space and really shouldn't count against GC. closes #1515 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Dec 4, 2017 at 11:38 UTC
c1e10dbc4e23e4ea41985cd08ffe4c3e4eca3083
2 files changed
+28
-5
test/sharness/lib/test-lib.sh
+21
@@ -394,6 +394,27 @@ file_size() {
394
$_STAT "$1"
395
}
396
397
+directory_size() {
398
+ local total=0
399
+ local fsize=0
400
+ local res=0
401
+ find "$1" -type f | ( while read fname; do
402
+ fsize=$(file_size "$fname")
403
+ res=$?
404
+ if ! test $? -eq 0; then
405
+ echo "failed to get filesize" >&2
406
+ return $res
407
+ fi
408
+ total=$(expr "$total" + "$fsize")
409
+ res=$?
410
+ if ! test $? -eq 0; then
411
+ echo "filesize not a number: $fsize" >&2
412
+ return $res
413
+ fi
414
+ done
415
+ echo "$total" ) # do not remove this subshell
416
+}
417
+
418
test_check_peerid() {
419
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
420
test "$peeridlen" = "46" || {
test/sharness/t0080-repo.sh
+7
-5
@@ -48,15 +48,17 @@ test_expect_success "'ipfs pin rm' output looks good" '
48
test_cmp expected1 actual1
49
'
50
51
-test_expect_failure "ipfs repo gc fully reverse ipfs add" '
51
+test_expect_success "ipfs repo gc fully reverse ipfs add" '
52
ipfs repo gc &&
53
random 100000 41 >gcfile &&
54
- disk_usage "$IPFS_PATH/blocks" >expected &&
55
- hash=`ipfs add -q gcfile` &&
54
+ expected="$(directory_size "$IPFS_PATH/blocks")" &&
55
+ find "$IPFS_PATH/blocks" -type f &&
56
+ hash=$(ipfs add -q gcfile) &&
57
ipfs pin rm -r $hash &&
58
ipfs repo gc &&
58
- disk_usage "$IPFS_PATH/blocks" >actual &&
59
- test_cmp expected actual
59
+ actual=$(directory_size "$IPFS_PATH/blocks") &&
60
+ { test "$actual" -eq "$expected" || test_fsh echo "$actual != $expected"; } &&
61
+ { test "$actual" -gt "0" || test_fsh echo "not($actual > 0)"; }
62
'
63
64
test_expect_success "file no longer pinned" '