]> arthur.barton.de Git - bup.git/blob - t/test-web.sh
tests: web: exit early to avoid indentation
[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 if test -z "$(type -p curl)"; then
32     WVSTART 'curl does not appear to be installed; skipping  test'
33     exit 0
34 fi
35     
36 WVPASS bup-python -c "import socket as s; s.socket(s.AF_UNIX).bind('socket')"
37 curl -s --unix-socket ./socket http://localhost/foo
38 if test $? -ne 7; then
39     WVSTART 'curl does not appear to support --unix-socket; skipping test'
40     exit 0
41 fi
42
43 if ! bup-python -c 'import tornado' 2> /dev/null; then
44     WVSTART 'unable to import tornado; skipping test'
45     exit 0
46 fi
47
48 WVSTART 'web'
49 WVPASS bup init
50 WVPASS mkdir src
51 WVPASS echo '¡excitement!' > src/data
52 WVPASS bup index src
53 WVPASS bup save -n '¡excitement!' --strip src
54
55 "$TOP/bup" web unix://socket &
56 web_pid=$!
57 wait-for-server-start
58
59 WVPASS curl --unix-socket ./socket \
60        'http://localhost/%C2%A1excitement%21/latest/data' > result
61 WVPASSEQ "$(curl --unix-socket ./socket http://localhost/static/styles.css)" \
62          "$(cat "$TOP/lib/web/static/styles.css")"
63
64 WVPASSEQ '¡excitement!' "$(cat result)"
65 WVPASS kill -s TERM "$web_pid"
66 WVPASS wait "$web_pid"
67
68 WVPASS rm -r "$tmpdir"