mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
Add ipfs-test-lib.sh and source it in sharness test-lib.sh
The new ipfs-test-lib.sh file contains generic test functions. We also start replacing fsh with a shell function named test_fsh() in ipfs-test-lib.sh. And we move our custom test_cmp in ipfs-test-lib.sh. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
parent
1afb281dfd
commit
65cbbdff84
18
test/ipfs-test-lib.sh
Normal file
18
test/ipfs-test-lib.sh
Normal file
@ -0,0 +1,18 @@
|
||||
# Generic test functions for go-ipfs
|
||||
|
||||
# Echo the args, run the cmd, and then also fail,
|
||||
# making sure a test case fails.
|
||||
test_fsh() {
|
||||
echo "> $@"
|
||||
eval "$@"
|
||||
echo ""
|
||||
false
|
||||
}
|
||||
|
||||
# Same as sharness' test_cmp but using test_fsh (to see the output).
|
||||
# We have to do it twice, so the first diff output doesn't show unless it's
|
||||
# broken.
|
||||
test_cmp() {
|
||||
diff -q "$@" >/dev/null || test_fsh diff -u "$@"
|
||||
}
|
||||
|
||||
@ -36,13 +36,6 @@ SHARNESS_LIB="lib/sharness/sharness.sh"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# overriding testcmp to make it use fsh (to see it better in output)
|
||||
# have to do it twice so the first diff output doesnt show unless it's
|
||||
# broken.
|
||||
test_cmp() {
|
||||
diff -q "$@" >/dev/null || fsh diff -u "$@"
|
||||
}
|
||||
|
||||
# Please put go-ipfs specific shell functions below
|
||||
|
||||
# grab + output options
|
||||
@ -55,6 +48,9 @@ if test "$TEST_VERBOSE" = 1; then
|
||||
echo '# TEST_EXPENSIVE='"$TEST_EXPENSIVE"
|
||||
fi
|
||||
|
||||
# source our generic test lib
|
||||
. ../../ipfs-test-lib.sh
|
||||
|
||||
test_cmp_repeat_10_sec() {
|
||||
for i in 1 2 3 4 5 6 7 8 9 10
|
||||
do
|
||||
@ -86,7 +82,7 @@ test_wait_output_n_lines_60_sec() {
|
||||
done
|
||||
done
|
||||
actual=$(cat "$1" | wc -l | tr -d " ")
|
||||
fsh "expected $2 lines of output. got $actual"
|
||||
test_fsh "expected $2 lines of output. got $actual"
|
||||
}
|
||||
|
||||
test_wait_open_tcp_port_10_sec() {
|
||||
@ -139,7 +135,7 @@ test_init_ipfs() {
|
||||
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
|
||||
test_config_set Mounts.IPNS "$(pwd)/ipns" &&
|
||||
ipfs bootstrap rm --all ||
|
||||
fsh cat "\"$IPFS_PATH/config\""
|
||||
test_fsh cat "\"$IPFS_PATH/config\""
|
||||
'
|
||||
|
||||
}
|
||||
@ -165,7 +161,7 @@ test_config_ipfs_gateway_writable() {
|
||||
|
||||
test_expect_success "prepare config -- gateway writable" '
|
||||
test_config_set -bool Gateway.Writable true ||
|
||||
fsh cat "\"$IPFS_PATH/config\""
|
||||
test_fsh cat "\"$IPFS_PATH/config\""
|
||||
'
|
||||
}
|
||||
|
||||
@ -181,13 +177,13 @@ test_launch_ipfs_daemon() {
|
||||
IPFS_PID=$! &&
|
||||
test_wait_output_n_lines_60_sec actual_daemon 2 &&
|
||||
test_run_repeat_60_sec "grep \"API server listening on $ADDR_API\" actual_daemon" ||
|
||||
fsh cat actual_daemon || fsh cat daemon_err
|
||||
test_fsh cat actual_daemon || test_fsh cat daemon_err
|
||||
'
|
||||
|
||||
if test "$ADDR_GWAY" != ""; then
|
||||
test_expect_success "'ipfs daemon' output includes Gateway address" '
|
||||
test_run_repeat_60_sec "grep \"Gateway server listening on $ADDR_GWAY\" actual_daemon" ||
|
||||
fsh cat daemon_err
|
||||
test_fsh cat daemon_err
|
||||
'
|
||||
fi
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user