Skip to content

Commit 686882b

Browse files
Merge pull request #3148 from ipfs/test/improve-verify
Improve sharness testing on ipfs repo verify
2 parents 050985c + 7baac76 commit 686882b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/sharness/t0086-repo-verify.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2016 Jeromy Johnson
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
7+
test_description="Test ipfs repo fsck"
8+
9+
. lib/test-lib.sh
10+
11+
test_init_ipfs
12+
13+
sort_rand() {
14+
case `uname` in
15+
Linux)
16+
sort -R
17+
;;
18+
Darwin)
19+
ruby -e 'puts STDIN.readlines.shuffle'
20+
;;
21+
*)
22+
echo "unsupported system: $(uname)"
23+
esac
24+
}
25+
26+
check_random_corruption() {
27+
to_break=$(find "$IPFS_PATH/blocks" -type f | sort_rand | head -n 1)
28+
29+
test_expect_success "back up file and overwrite it" '
30+
cp "$to_break" backup_file &&
31+
echo "this is super broken" > "$to_break"
32+
'
33+
34+
test_expect_success "repo verify detects failure" '
35+
test_expect_code 1 ipfs repo verify
36+
'
37+
38+
test_expect_success "replace the object" '
39+
cp backup_file "$to_break"
40+
'
41+
42+
test_expect_success "ipfs repo verify passes just fine now" '
43+
ipfs repo verify
44+
'
45+
}
46+
47+
test_expect_success "create some files" '
48+
random-files -depth=3 -dirs=4 -files=10 foobar > /dev/null
49+
'
50+
51+
test_expect_success "add them all" '
52+
ipfs add -r -q foobar > /dev/null
53+
'
54+
55+
for i in `seq 20`
56+
do
57+
check_random_corruption
58+
done
59+
60+
test_done

0 commit comments

Comments
 (0)