Skip to content

Commit

Permalink
Merge pull request #5364 from ipfs/fix/1515
Browse files Browse the repository at this point in the history
add correct test for 1515
  • Loading branch information
Stebalien authored Aug 13, 2018
2 parents 95d53bf + c1e10db commit 0e5ed59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
21 changes: 21 additions & 0 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,27 @@ file_size() {
$_STAT "$1"
}

directory_size() {
local total=0
local fsize=0
local res=0
find "$1" -type f | ( while read fname; do
fsize=$(file_size "$fname")
res=$?
if ! test $? -eq 0; then
echo "failed to get filesize" >&2
return $res
fi
total=$(expr "$total" + "$fsize")
res=$?
if ! test $? -eq 0; then
echo "filesize not a number: $fsize" >&2
return $res
fi
done
echo "$total" ) # do not remove this subshell
}

test_check_peerid() {
peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") &&
test "$peeridlen" = "46" || {
Expand Down
12 changes: 7 additions & 5 deletions test/sharness/t0080-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ test_expect_success "'ipfs pin rm' output looks good" '
test_cmp expected1 actual1
'

test_expect_failure "ipfs repo gc fully reverse ipfs add" '
test_expect_success "ipfs repo gc fully reverse ipfs add" '
ipfs repo gc &&
random 100000 41 >gcfile &&
disk_usage "$IPFS_PATH/blocks" >expected &&
hash=`ipfs add -q gcfile` &&
expected="$(directory_size "$IPFS_PATH/blocks")" &&
find "$IPFS_PATH/blocks" -type f &&
hash=$(ipfs add -q gcfile) &&
ipfs pin rm -r $hash &&
ipfs repo gc &&
disk_usage "$IPFS_PATH/blocks" >actual &&
test_cmp expected actual
actual=$(directory_size "$IPFS_PATH/blocks") &&
{ test "$actual" -eq "$expected" || test_fsh echo "$actual != $expected"; } &&
{ test "$actual" -gt "0" || test_fsh echo "not($actual > 0)"; }
'

test_expect_success "file no longer pinned" '
Expand Down

0 comments on commit 0e5ed59

Please sign in to comment.