]> arthur.barton.de Git - bup.git/blob - test/ext/test-web
Teach pytest to handle WVSKIP and use it where we can
[bup.git] / test / ext / test-web
1 #!/usr/bin/env bash
2 . wvtest-bup.sh || exit $?
3 . dev/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 if test -z "$(type -p curl)"; then
31     WVSKIP 'curl does not appear to be installed; skipping test'
32     exit 0
33 fi
34     
35 WVPASS bup-cfg-py -c "import socket as s; s.socket(s.AF_UNIX).bind('socket')"
36 curl -s --unix-socket ./socket http://localhost/foo
37 if test $? -ne 7; then
38     WVSKIP 'curl does not appear to support --unix-socket; skipping test'
39     exit 0
40 fi
41
42 if ! bup-python -c 'import tornado' 2> /dev/null; then
43     WVSKIP 'unable to import tornado; skipping test'
44     exit 0
45 fi
46
47 WVSTART 'web'
48 WVPASS bup init
49 WVPASS mkdir src
50 WVPASS echo '¡excitement!' > src/data
51 WVPASS echo -e 'whee \x80\x90\xff' > "$(echo -ne 'src/whee \x80\x90\xff')"
52 WVPASS bup index src
53 WVPASS bup save -n '¡excitement!' --strip src
54
55 "$TOP/bup" web unix://socket </dev/null >bup-web.log 2>&1 &
56 web_pid=$!
57 # output the log if something fails
58 trap 'cat bup-web.log' EXIT
59 wait-for-server-start
60
61 WVPASS curl --unix-socket ./socket \
62        'http://localhost/%C2%A1excitement%21/latest/data' > result
63 WVPASS curl --unix-socket ./socket \
64        'http://localhost/%C2%A1excitement%21/latest/whee%20%80%90%ff' > result2
65 WVPASSEQ "$(curl --unix-socket ./socket http://localhost/static/styles.css)" \
66          "$(cat "$TOP/lib/web/static/styles.css")"
67
68 WVPASSEQ '¡excitement!' "$(cat result)"
69 WVPASS cmp "$(echo -ne 'src/whee \x80\x90\xff')" result2
70 WVPASS kill -s TERM "$web_pid"
71 WVPASS wait "$web_pid"
72
73 trap - EXIT
74 WVPASS rm -r "$tmpdir"