Commit 739abea3 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #647 from chriscool/ipfs_test_lib

Add ipfs-test-lib.sh
parents 65997561 bbb6196d
#!/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
# 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 "$@"
}
......@@ -52,12 +52,12 @@ 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
test_fsh ls -al .go-ipfs
'
```
The `|| ...` is a diagnostic run when the preceding command fails.
`bin/fsh` is a trivial script that echoes the args, runs the cmd,
test_fsh is a shell function 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!).
......
......@@ -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
}
......
......@@ -18,7 +18,7 @@ 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]" >/dev/null ||
fsh cat version.txt
test_fsh cat version.txt
'
test_expect_success "ipfs help succeeds" '
......@@ -28,7 +28,7 @@ test_expect_success "ipfs help succeeds" '
test_expect_success "ipfs help output looks good" '
cat help.txt | egrep -i "^Usage:" >/dev/null &&
cat help.txt | egrep "ipfs .* <command>" >/dev/null ||
fsh cat help.txt
test_fsh cat help.txt
'
test_done
......@@ -18,7 +18,7 @@ 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
test_fsh ls -al .go-ipfs
'
test_expect_success "ipfs config succeeds" '
......
......@@ -27,7 +27,7 @@ test_expect_failure "'ipfs mount' fails when no mount dir (issue #341)" '
test_expect_failure "'ipfs mount' looks good when it fails (issue #341)" '
! grep "IPFS mounted at: $(pwd)/ipfs" actual >/dev/null &&
! grep "IPNS mounted at: $(pwd)/ipns" actual >/dev/null ||
fsh cat actual
test_fsh cat actual
'
# now mount properly, and keep going
......
......@@ -16,7 +16,7 @@ test_expect_success "'ipfs add --help' succeeds" '
test_expect_success "'ipfs add --help' output looks good" '
egrep "ipfs add.*<path>" actual >/dev/null ||
fsh cat actual
test_fsh cat actual
'
test_expect_success "'ipfs cat --help' succeeds" '
......@@ -25,7 +25,7 @@ test_expect_success "'ipfs cat --help' succeeds" '
test_expect_success "'ipfs cat --help' output looks good" '
egrep "ipfs cat.*<ipfs-path>" actual >/dev/null ||
fsh cat actual
test_fsh cat actual
'
test_expect_success "ipfs add succeeds" '
......
......@@ -48,7 +48,7 @@ test_expect_success ".go-ipfs/ has been created" '
test -d ".go-ipfs" &&
test -f ".go-ipfs/config" &&
test -d ".go-ipfs/datastore" ||
fsh ls .go-ipfs
test_fsh ls .go-ipfs
'
test_expect_success "daemon is still running" '
......
......@@ -17,7 +17,7 @@ test_expect_success "'ipfs get --help' succeeds" '
test_expect_success "'ipfs get --help' output looks good" '
egrep "ipfs get.*<ipfs-path>" actual >/dev/null ||
fsh cat actual
test_fsh cat actual
'
test_expect_success "ipfs get succeeds" '
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment