@cryptotaxi247 / kubo / commits / 65cbbdff8

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>

Christian Couder committed Jan 24, 2015 at 21:00 UTC 65cbbdff8426d519bab839dcd147c3cbf4d8d6da
2 files changed +26 -12
test/ipfs-test-lib.sh new
+18
@@ -0,0 +1,18 @@
1 +# Generic test functions for go-ipfs
2 +
3 +# Echo the args, run the cmd, and then also fail,
4 +# making sure a test case fails.
5 +test_fsh() {
6 + echo "> $@"
7 + eval "$@"
8 + echo ""
9 + false
10 +}
11 +
12 +# Same as sharness' test_cmp but using test_fsh (to see the output).
13 +# We have to do it twice, so the first diff output doesn't show unless it's
14 +# broken.
15 +test_cmp() {
16 + diff -q "$@" >/dev/null || test_fsh diff -u "$@"
17 +}
18 +
test/sharness/lib/test-lib.sh
+8 -12
@@ -36,13 +36,6 @@ SHARNESS_LIB="lib/sharness/sharness.sh"
36 exit 1
37 }
38
39 -# overriding testcmp to make it use fsh (to see it better in output)
40 -# have to do it twice so the first diff output doesnt show unless it's
41 -# broken.
42 -test_cmp() {
43 - diff -q "$@" >/dev/null || fsh diff -u "$@"
44 -}
45 -
39 # Please put go-ipfs specific shell functions below
40
41 # grab + output options
@@ -55,6 +48,9 @@ if test "$TEST_VERBOSE" = 1; then
48 echo '# TEST_EXPENSIVE='"$TEST_EXPENSIVE"
49 fi
50
51 +# source our generic test lib
52 +. ../../ipfs-test-lib.sh
53 +
54 test_cmp_repeat_10_sec() {
55 for i in 1 2 3 4 5 6 7 8 9 10
56 do
@@ -86,7 +82,7 @@ test_wait_output_n_lines_60_sec() {
82 done
83 done
84 actual=$(cat "$1" | wc -l | tr -d " ")
89 - fsh "expected $2 lines of output. got $actual"
85 + test_fsh "expected $2 lines of output. got $actual"
86 }
87
88 test_wait_open_tcp_port_10_sec() {
@@ -139,7 +135,7 @@ test_init_ipfs() {
135 test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
136 test_config_set Mounts.IPNS "$(pwd)/ipns" &&
137 ipfs bootstrap rm --all ||
142 - fsh cat "\"$IPFS_PATH/config\""
138 + test_fsh cat "\"$IPFS_PATH/config\""
139 '
140
141 }
@@ -165,7 +161,7 @@ test_config_ipfs_gateway_writable() {
161
162 test_expect_success "prepare config -- gateway writable" '
163 test_config_set -bool Gateway.Writable true ||
168 - fsh cat "\"$IPFS_PATH/config\""
164 + test_fsh cat "\"$IPFS_PATH/config\""
165 '
166 }
167
@@ -181,13 +177,13 @@ test_launch_ipfs_daemon() {
177 IPFS_PID=$! &&
178 test_wait_output_n_lines_60_sec actual_daemon 2 &&
179 test_run_repeat_60_sec "grep \"API server listening on $ADDR_API\" actual_daemon" ||
184 - fsh cat actual_daemon || fsh cat daemon_err
180 + test_fsh cat actual_daemon || test_fsh cat daemon_err
181 '
182
183 if test "$ADDR_GWAY" != ""; then
184 test_expect_success "'ipfs daemon' output includes Gateway address" '
185 test_run_repeat_60_sec "grep \"Gateway server listening on $ADDR_GWAY\" actual_daemon" ||
190 - fsh cat daemon_err
186 + test_fsh cat daemon_err
187 '
188 fi
189 }