mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
sharness: nice verbose ouput
Make sharness tests' output helpful when verbose. This means cating certain files, or running diagnostic commands. I used a construction like: test_expect_success ".go-ipfs/ has been created" ' test -d ".go-ipfs" && test -f ".go-ipfs/config" && test -d ".go-ipfs/datastore" || fsh ls -al .go-ipfs ' The `|| ...` is a diagnostic run when the preceding command fails. `fsh` is a trivial script that echoes the args, runs the cmd, and then also fails, making sure the test case fails. (wouldnt want the diagnostic accidentally returning true and making it _seem_ like the test case succeeded).
This commit is contained in:
13
test/bin/fsh
Executable file
13
test/bin/fsh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Author: Juan Batiz-Benet <juan@benet.ai>
|
||||
# MIT LICENSED
|
||||
|
||||
# verbose eval, and exit with error, so we can avoid writing:
|
||||
# echo "cat version.txt" && cat version.txt && false
|
||||
|
||||
# echo "# > $@"
|
||||
# eval $@ | sed -e 's/^/# /'
|
||||
echo "> $@"
|
||||
eval $@
|
||||
echo ""
|
||||
exit 1
|
@ -39,7 +39,7 @@ test "$TEST_EXPENSIVE" = 1 && test_set_prereq EXPENSIVE
|
||||
test_cmp_repeat_10_sec() {
|
||||
for i in 1 2 3 4 5 6 7 8 9 10
|
||||
do
|
||||
test_cmp "$1" "$2" && return
|
||||
test_cmp "$1" "$2" >/dev/null && return
|
||||
sleep 1
|
||||
done
|
||||
test_cmp "$1" "$2"
|
||||
@ -57,24 +57,11 @@ test_wait_output_n_lines_60_sec() {
|
||||
test_cmp "expected_waitn" "actual_waitn"
|
||||
}
|
||||
|
||||
test_launch_ipfs_daemon() {
|
||||
|
||||
test_expect_success FUSE "'ipfs daemon' succeeds" '
|
||||
ipfs daemon >actual &
|
||||
'
|
||||
|
||||
test_expect_success FUSE "'ipfs daemon' output looks good" '
|
||||
IPFS_PID=$! &&
|
||||
echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected &&
|
||||
test_cmp_repeat_10_sec expected actual
|
||||
'
|
||||
}
|
||||
|
||||
test_launch_ipfs_daemon_and_mount() {
|
||||
test_init_ipfs() {
|
||||
|
||||
test_expect_success "ipfs init succeeds" '
|
||||
export IPFS_DIR="$(pwd)/.go-ipfs" &&
|
||||
ipfs init -b=1024
|
||||
ipfs init -b=1024 > /dev/null
|
||||
'
|
||||
|
||||
test_expect_success "prepare config" '
|
||||
@ -83,7 +70,23 @@ test_launch_ipfs_daemon_and_mount() {
|
||||
ipfs config Mounts.IPNS "$(pwd)/ipns"
|
||||
'
|
||||
|
||||
test_launch_ipfs_daemon
|
||||
}
|
||||
|
||||
test_launch_ipfs_daemon() {
|
||||
|
||||
test_expect_success FUSE "'ipfs daemon' succeeds" '
|
||||
ipfs daemon >actual 2>daemon_err &
|
||||
'
|
||||
|
||||
test_expect_success FUSE "'ipfs daemon' output looks good" '
|
||||
IPFS_PID=$! &&
|
||||
echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected &&
|
||||
test_cmp_repeat_10_sec expected actual ||
|
||||
fsh cat daemon_err
|
||||
'
|
||||
}
|
||||
|
||||
test_mount_ipfs() {
|
||||
|
||||
test_expect_success FUSE "'ipfs mount' succeeds" '
|
||||
ipfs mount >actual
|
||||
@ -94,6 +97,15 @@ test_launch_ipfs_daemon_and_mount() {
|
||||
echo "IPNS mounted at: $(pwd)/ipns" >>expected &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
}
|
||||
|
||||
test_launch_ipfs_daemon_and_mount() {
|
||||
|
||||
test_init_ipfs
|
||||
test_launch_ipfs_daemon
|
||||
test_mount_ipfs
|
||||
|
||||
}
|
||||
|
||||
test_kill_repeat_10_sec() {
|
||||
|
@ -17,7 +17,8 @@ test_expect_success "ipfs version succeeds" '
|
||||
'
|
||||
|
||||
test_expect_success "ipfs version output looks good" '
|
||||
cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]"
|
||||
cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" >/dev/null ||
|
||||
fsh cat version.txt
|
||||
'
|
||||
|
||||
test_expect_success "ipfs help succeeds" '
|
||||
@ -25,9 +26,9 @@ test_expect_success "ipfs help succeeds" '
|
||||
'
|
||||
|
||||
test_expect_success "ipfs help output looks good" '
|
||||
cat help.txt | egrep -i "^Usage:" &&
|
||||
cat help.txt | egrep "ipfs .* <command>"
|
||||
cat help.txt | egrep -i "^Usage:" >/dev/null &&
|
||||
cat help.txt | egrep "ipfs .* <command>" >/dev/null ||
|
||||
fsh cat help.txt
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
|
@ -16,7 +16,8 @@ test_expect_success "ipfs init succeeds" '
|
||||
test_expect_success ".go-ipfs/ has been created" '
|
||||
test -d ".go-ipfs" &&
|
||||
test -f ".go-ipfs/config" &&
|
||||
test -d ".go-ipfs/datastore"
|
||||
test -d ".go-ipfs/datastore" ||
|
||||
fsh ls -al .go-ipfs
|
||||
'
|
||||
|
||||
test_expect_success "ipfs config succeeds" '
|
||||
|
@ -15,25 +15,32 @@ if ! test_have_prereq FUSE; then
|
||||
test_done
|
||||
fi
|
||||
|
||||
test_launch_ipfs_daemon_and_mount
|
||||
|
||||
test_kill_ipfs_daemon
|
||||
|
||||
test_expect_success "mount directories can be removed" '
|
||||
rmdir ipfs ipns
|
||||
'
|
||||
|
||||
test_init_ipfs
|
||||
test_launch_ipfs_daemon
|
||||
|
||||
# run this mount failure before mounting properly.
|
||||
|
||||
test_expect_failure "'ipfs mount' fails when no mount dir (issue #341)" '
|
||||
test_must_fail ipfs mount >actual
|
||||
test_must_fail ipfs mount -f=not_ipfs -n=not_ipns >actual
|
||||
'
|
||||
|
||||
test_expect_failure "'ipfs mount' looks good when it fails (issue #341)" '
|
||||
! grep "IPFS mounted at" actual &&
|
||||
! grep "IPNS mounted at" actual
|
||||
! grep "IPFS mounted at: $(pwd)/ipfs" actual >/dev/null &&
|
||||
! grep "IPNS mounted at: $(pwd)/ipns" actual >/dev/null ||
|
||||
fsh cat actual
|
||||
'
|
||||
|
||||
# now mount properly, and keep going
|
||||
test_mount_ipfs
|
||||
|
||||
test_expect_success "mount directories cannot be removed while active" '
|
||||
test_must_fail rmdir ipfs ipns 2>/dev/null
|
||||
'
|
||||
|
||||
test_kill_ipfs_daemon
|
||||
|
||||
test_expect_success "mount directories can be removed after shutdown" '
|
||||
rmdir ipfs ipns
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -15,7 +15,8 @@ test_expect_success "'ipfs add --help' succeeds" '
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs add --help' output looks good" '
|
||||
egrep "ipfs add.*<path>" actual
|
||||
egrep "ipfs add.*<path>" actual >/dev/null ||
|
||||
fsh cat actual
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs cat --help' succeeds" '
|
||||
@ -23,7 +24,8 @@ test_expect_success "'ipfs cat --help' succeeds" '
|
||||
'
|
||||
|
||||
test_expect_success "'ipfs cat --help' output looks good" '
|
||||
egrep "ipfs cat.*<ipfs-path>" actual
|
||||
egrep "ipfs cat.*<ipfs-path>" actual >/dev/null ||
|
||||
fsh cat actual
|
||||
'
|
||||
|
||||
test_expect_success "ipfs add succeeds" '
|
||||
|
@ -8,10 +8,7 @@ test_description="Test block command"
|
||||
|
||||
. lib/test-lib.sh
|
||||
|
||||
test_expect_success "ipfs init succeeds" '
|
||||
export IPFS_DIR="$(pwd)/.go-ipfs" &&
|
||||
ipfs init
|
||||
'
|
||||
test_init_ipfs
|
||||
|
||||
test_expect_success "'ipfs block put' succeeds" '
|
||||
echo "Hello Mars!" >expected_in &&
|
||||
|
@ -46,7 +46,8 @@ test_expect_success "ipfs daemon output looks good" '
|
||||
test_expect_success ".go-ipfs/ has been created" '
|
||||
test -d ".go-ipfs" &&
|
||||
test -f ".go-ipfs/config" &&
|
||||
test -d ".go-ipfs/datastore"
|
||||
test -d ".go-ipfs/datastore" ||
|
||||
fsh ls .go-ipfs
|
||||
'
|
||||
|
||||
test_expect_success "daemon is still running" '
|
||||
|
Reference in New Issue
Block a user