]> arthur.barton.de Git - bup.git/blob - t/test-web.sh
test-restore-map-owner: accommodate python 3 and test there
[bup.git] / t / test-web.sh
1 #!/usr/bin/env bash
2 . wvtest-bup.sh || exit $?
3 . t/lib.sh || exit $?
4
5 set -o pipefail
6
7 TOP="$(WVPASS pwd)" || exit $?
8 tmpdir="$(WVPASS wvmktempdir)" || exit $?
9 export BUP_DIR="$tmpdir/bup"
10
11 bup()
12 {
13     "$TOP/bup" "$@"
14 }
15
16 wait-for-server-start()
17 {
18     curl --unix-socket ./socket http://localhost/
19     curl_status=$?
20     while test $curl_status -eq 7; do
21         sleep 0.2
22         curl --unix-socket ./socket http://localhost/
23         curl_status=$?
24     done
25     WVPASSEQ $curl_status 0
26 }
27
28 WVPASS cd "$tmpdir"
29
30 # FIXME: add WVSKIP
31 run_test=true
32
33 if test -z "$(type -p curl)"; then
34     WVSTART 'curl does not appear to be installed; skipping  test'
35     run_test=''
36 fi
37     
38 WVPASS bup-python -c "import socket as s; s.socket(s.AF_UNIX).bind('socket')"
39 curl -s --unix-socket ./socket http://localhost/foo
40 if test $? -ne 7; then
41     WVSTART 'curl does not appear to support --unix-socket; skipping test'
42     run_test=''
43 fi
44
45 if ! bup-python -c 'import tornado' 2> /dev/null; then
46     WVSTART 'unable to import tornado; skipping test'
47     run_test=''
48 fi
49
50 if test -n "$run_test"; then
51     WVSTART 'web'
52     WVPASS bup init
53     WVPASS mkdir src
54     WVPASS echo '¡excitement!' > src/data
55     WVPASS bup index src
56     WVPASS bup save -n '¡excitement!' --strip src
57
58     "$TOP/bup" web unix://socket &
59     web_pid=$!
60     wait-for-server-start
61
62     WVPASS curl --unix-socket ./socket \
63            'http://localhost/%C2%A1excitement%21/latest/data' > result
64     WVPASSEQ "$(curl --unix-socket ./socket http://localhost/static/styles.css)" \
65              "$(cat "$TOP/lib/web/static/styles.css")"
66
67     WVPASSEQ '¡excitement!' "$(cat result)"
68     WVPASS kill -s TERM "$web_pid"
69     WVPASS wait "$web_pid"
70 fi
71
72 WVPASS rm -r "$tmpdir"