mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 03:47:45 +08:00
repo/verify: add better testing on repo verify command
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
parent
050985c52b
commit
7baac76a3b
60
test/sharness/t0086-repo-verify.sh
Executable file
60
test/sharness/t0086-repo-verify.sh
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2016 Jeromy Johnson
|
||||
# MIT Licensed; see the LICENSE file in this repository.
|
||||
#
|
||||
|
||||
test_description="Test ipfs repo fsck"
|
||||
|
||||
. lib/test-lib.sh
|
||||
|
||||
test_init_ipfs
|
||||
|
||||
sort_rand() {
|
||||
case `uname` in
|
||||
Linux)
|
||||
sort -R
|
||||
;;
|
||||
Darwin)
|
||||
ruby -e 'puts STDIN.readlines.shuffle'
|
||||
;;
|
||||
*)
|
||||
echo "unsupported system: $(uname)"
|
||||
esac
|
||||
}
|
||||
|
||||
check_random_corruption() {
|
||||
to_break=$(find "$IPFS_PATH/blocks" -type f | sort_rand | head -n 1)
|
||||
|
||||
test_expect_success "back up file and overwrite it" '
|
||||
cp "$to_break" backup_file &&
|
||||
echo "this is super broken" > "$to_break"
|
||||
'
|
||||
|
||||
test_expect_success "repo verify detects failure" '
|
||||
test_expect_code 1 ipfs repo verify
|
||||
'
|
||||
|
||||
test_expect_success "replace the object" '
|
||||
cp backup_file "$to_break"
|
||||
'
|
||||
|
||||
test_expect_success "ipfs repo verify passes just fine now" '
|
||||
ipfs repo verify
|
||||
'
|
||||
}
|
||||
|
||||
test_expect_success "create some files" '
|
||||
random-files -depth=3 -dirs=4 -files=10 foobar > /dev/null
|
||||
'
|
||||
|
||||
test_expect_success "add them all" '
|
||||
ipfs add -r -q foobar > /dev/null
|
||||
'
|
||||
|
||||
for i in `seq 20`
|
||||
do
|
||||
check_random_corruption
|
||||
done
|
||||
|
||||
test_done
|
||||
Loading…
Reference in New Issue
Block a user