Git 2.23
[gitweb.git] / t / lib-httpd.sh
index f9f3e5fd82e1b34d87993f750bd05e46e69bd82c..0d985758c6dd85e801404860ee82c5e93f1b51d9 100644 (file)
@@ -14,7 +14,6 @@
 #
 #      test_expect_success ...
 #
-#      stop_httpd
 #      test_done
 #
 # Can be configured using the following variables.
@@ -24,7 +23,7 @@
 #    LIB_HTTPD_MODULE_PATH       web server modules path
 #    LIB_HTTPD_PORT              listening port
 #    LIB_HTTPD_DAV               enable DAV
-#    LIB_HTTPD_SVN               enable SVN
+#    LIB_HTTPD_SVN               enable SVN at given location (e.g. "svn")
 #    LIB_HTTPD_SSL               enable SSL
 #
 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
@@ -42,15 +41,14 @@ then
        test_done
 fi
 
-test_tristate GIT_TEST_HTTPD
-if test "$GIT_TEST_HTTPD" = false
+if ! git env--helper --type=bool --default=true --exit-code GIT_TEST_HTTPD
 then
        skip_all="Network testing disabled (unset GIT_TEST_HTTPD to enable)"
        test_done
 fi
 
 if ! test_have_prereq NOT_ROOT; then
-       test_skip_or_die $GIT_TEST_HTTPD \
+       test_skip_or_die GIT_TEST_HTTPD \
                "Cannot run httpd tests as root"
 fi
 
@@ -82,7 +80,7 @@ case $(uname) in
 esac
 
 LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
-LIB_HTTPD_PORT=${LIB_HTTPD_PORT-${this_test#t}}
+test_set_port LIB_HTTPD_PORT
 
 TEST_PATH="$TEST_DIRECTORY"/lib-httpd
 HTTPD_ROOT_PATH="$PWD"/httpd
@@ -91,11 +89,12 @@ HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
 # hack to suppress apache PassEnv warnings
 GIT_VALGRIND=$GIT_VALGRIND; export GIT_VALGRIND
 GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS
+GIT_TEST_SIDEBAND_ALL=$GIT_TEST_SIDEBAND_ALL; export GIT_TEST_SIDEBAND_ALL
 GIT_TRACE=$GIT_TRACE; export GIT_TRACE
 
 if ! test -x "$LIB_HTTPD_PATH"
 then
-       test_skip_or_die $GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'"
+       test_skip_or_die GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'"
 fi
 
 HTTPD_VERSION=$($LIB_HTTPD_PATH -v | \
@@ -107,19 +106,19 @@ then
        then
                if ! test $HTTPD_VERSION -ge 2
                then
-                       test_skip_or_die $GIT_TEST_HTTPD \
+                       test_skip_or_die GIT_TEST_HTTPD \
                                "at least Apache version 2 is required"
                fi
                if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
                then
-                       test_skip_or_die $GIT_TEST_HTTPD \
+                       test_skip_or_die GIT_TEST_HTTPD \
                                "Apache module directory not found"
                fi
 
                LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
        fi
 else
-       test_skip_or_die $GIT_TEST_HTTPD \
+       test_skip_or_die GIT_TEST_HTTPD \
                "Could not identify web server at '$LIB_HTTPD_PATH'"
 fi
 
@@ -131,7 +130,9 @@ prepare_httpd() {
        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
        cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
        install_script broken-smart-http.sh
+       install_script error-smart-http.sh
        install_script error.sh
+       install_script apply-one-time-sed.sh
 
        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
 
@@ -162,8 +163,10 @@ prepare_httpd() {
                if test -n "$LIB_HTTPD_SVN"
                then
                        HTTPD_PARA="$HTTPD_PARA -DSVN"
-                       rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
-                       svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
+                       LIB_HTTPD_SVNPATH="$rawsvnrepo"
+                       svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/"
+                       svnrepo="$svnrepo$LIB_HTTPD_SVN"
+                       export LIB_HTTPD_SVN LIB_HTTPD_SVNPATH
                fi
        fi
 }
@@ -171,7 +174,7 @@ prepare_httpd() {
 start_httpd() {
        prepare_httpd >&3 2>&4
 
-       trap 'code=$?; stop_httpd; (exit $code); die' EXIT
+       test_atexit stop_httpd
 
        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
                -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
@@ -179,14 +182,12 @@ start_httpd() {
                >&3 2>&4
        if test $? -ne 0
        then
-               trap 'die' EXIT
-               test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
+               cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
+               test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
        fi
 }
 
 stop_httpd() {
-       trap 'die' EXIT
-
        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
                -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
 }
@@ -284,3 +285,24 @@ expect_askpass() {
        test_cmp "$TRASH_DIRECTORY/askpass-expect" \
                 "$TRASH_DIRECTORY/askpass-query"
 }
+
+strip_access_log() {
+       sed -e "
+               s/^.* \"//
+               s/\"//
+               s/ [1-9][0-9]*\$//
+               s/^GET /GET  /
+       " "$HTTPD_ROOT_PATH"/access.log
+}
+
+# Requires one argument: the name of a file containing the expected stripped
+# access log entries.
+check_access_log() {
+       sort "$1" >"$1".sorted &&
+       strip_access_log >access.log.stripped &&
+       sort access.log.stripped >access.log.sorted &&
+       if ! test_cmp "$1".sorted access.log.sorted
+       then
+               test_cmp "$1" access.log.stripped
+       fi
+}