[PATCH] http-push: add regression tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



http-push tests require a web server with WebDAV support.

This commit introduces a HTTPD test library, which can be configured using
the following environment variables.

LIB_HTTPD_PATH	web server path
LIB_HTTPD_PORT	listening port
LIB_HTTPD_DAV	enable DAV
LIB_HTTPD_SVN	enable SVN
LIB_HTTPD_SSL	enable SSL

Signed-off-by: Clemens Buchacher <drizzd@xxxxxx>
---

On Sun, Feb 24, 2008 at 09:58:30AM +0100, Mike Hommey wrote:
> > +LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
> > +LoadModule dav_fs_module /usr/lib/apache2/modules/mod_dav_fs.so
> 
> You'd need something for these paths too.

Indeed. If Apache or the DAV modules are not found, the test is now skipped. If
Apache is older than version 2, the test is skipped as well. I had some
problems with WebDAV "lock tokens" and couldn't get http-push to work. In
principle, however, lib-http.sh also works with Apache version 1.3.

If LIB_HTTPD_PATH points to an executable, but not to an Apache web server, the
test fails with an error.

> It would be nice if the httpd setup could be done in another file so
> that other tests could use it. Also, an https setup would be nice ;)

Good idea.

I also added SVN support. I simply tried to mimic the code from lib-git-svn.sh.
It should be straightforward to integrate lib-httpd.sh into lib-git-svn.sh now.

Regards,
Clemens

 t/lib-httpd.sh       |  181 ++++++++++++++++++++++++++++++++++++++++++++++++++
 t/t5540-http-push.sh |   83 +++++++++++++++++++++++
 2 files changed, 264 insertions(+), 0 deletions(-)
 create mode 100644 t/lib-httpd.sh
 create mode 100644 t/t5540-http-push.sh

diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh
new file mode 100644
index 0000000..7fc090e
--- /dev/null
+++ b/t/lib-httpd.sh
@@ -0,0 +1,181 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Clemens Buchacher <drizzd@xxxxxx>
+#
+
+LIB_HTTPD_ROOT_PATH=${LIB_HTTPD_ROOT_PATH-"$PWD"}
+LIB_HTTPD_PATH=${LIB_HTTPD_PATH-'/usr/sbin/apache2'}
+
+if test -x "$LIB_HTTPD_PATH"; then
+
+HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
+	sed -n 's/^Server version: Apache\/\([0-9\.]*\).*$/\1/p'`
+HTTPD_VERSION_MAJOR=$((`echo $HTTPD_VERSION | sed 's/\..*//'`))
+HTTPD_VERSION_MINOR=\
+$((`echo $HTTPD_VERSION | sed 's/^[0-9]*\.//' | sed 's/\..*//'`))
+
+if test -n "$HTTPD_VERSION"
+then
+	if test -z "$LIB_HTTPD_MODULE_PATH"
+	then
+		if test $HTTPD_VERSION_MAJOR -ge 2
+		then
+			LIB_HTTPD_MODULE_PATH='/usr/lib/apache2/modules'
+		else
+			HTTPD_VERSION_SHORT=$HTTPD_VERSION_MAJOR.$HTTPD_VERSION_MINOR
+			LIB_HTTPD_MODULE_PATH="/usr/lib/apache/$HTTPD_VERSION_SHORT"
+		fi
+	fi
+else
+	error "Could not identify web server '$LIB_HTTPD_PATH'"
+fi
+
+fi # test -x "$LIB_HTTPD_PATH"
+
+LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
+
+if test -z "$LIB_HTTPD_SSL"
+then
+	HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
+else
+	HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
+fi
+
+conf_init() {
+	test $# -eq 0 ||
+	error "error: not 0 parameters to conf_init"
+
+	: >"$LIB_HTTPD_ROOT_PATH/httpd.conf"
+}
+
+conf_write() {
+	test $# -eq 0 ||
+	error "error: not 0 parameters to conf_write"
+
+	cat >> "$LIB_HTTPD_ROOT_PATH/httpd.conf"
+}
+
+conf_load_module() {
+	test $# -eq 2 ||
+	error "error: not 2 parameters to conf_load_module"
+
+	if ! test -f $LIB_HTTPD_MODULE_PATH/$2
+	then
+		test_expect_success "Could find $1 at $LIB_HTTPD_MODULE_PATH/$2" :
+		test_done
+		exit
+	fi
+
+	conf_write <<EOF
+LoadModule $1 $LIB_HTTPD_MODULE_PATH/$2
+EOF
+}
+
+prepare_httpd() {
+	test $# -eq 0 ||
+	error "error: not 0 parameters to prepare_httpd"
+
+	conf_write <<EOF
+ServerRoot $LIB_HTTPD_ROOT_PATH
+PidFile $LIB_HTTPD_ROOT_PATH/httpd.pid
+DocumentRoot $LIB_HTTPD_ROOT_PATH
+ErrorLog $LIB_HTTPD_ROOT_PATH/error.log
+Listen 127.0.0.1:$LIB_HTTPD_PORT
+EOF
+
+	if test "$LIB_HTTPD_SSL" != ""
+	then
+		cat > $LIB_HTTPD_ROOT_PATH/ssl.cnf <<EOF
+RANDFILE                = $ENV::HOME/.rnd
+
+[ req ]
+default_bits            = 1024
+distinguished_name      = req_distinguished_name
+prompt                  = no
+[ req_distinguished_name ]
+commonName                      = 127.0.0.1
+EOF
+		openssl req \
+			-config $LIB_HTTPD_ROOT_PATH/ssl.cnf \
+			-new -x509 -nodes \
+			-out $LIB_HTTPD_ROOT_PATH/httpd.pem \
+			-keyout $LIB_HTTPD_ROOT_PATH/httpd.pem
+		export GIT_SSL_NO_VERIFY=t
+		conf_load_module ssl_module mod_ssl.so
+		conf_write <<EOF
+SSLCertificateFile $LIB_HTTPD_ROOT_PATH/httpd.pem
+SSLCertificateKeyFile $LIB_HTTPD_ROOT_PATH/httpd.pem
+SSLRandomSeed startup file:/dev/urandom 512
+SSLRandomSeed connect file:/dev/urandom 512
+SSLSessionCache none
+SSLMutex file:$LIB_HTTPD_ROOT_PATH/ssl_mutex
+SSLEngine On
+EOF
+	fi
+		
+	if test "$LIB_HTTPD_DAV" != "" -o "$LIB_HTTPD_SVN" != ""
+	then
+		if test $HTTPD_VERSION_MAJOR -ge 2
+		then
+			conf_load_module dav_module mod_dav.so
+		else
+			conf_load_module dav_module libdav.so
+		fi
+
+		if test $HTTPD_VERSION_MAJOR -ge 2
+		then
+			conf_load_module dav_fs_module mod_dav_fs.so
+		fi
+
+		conf_write <<EOF
+DAVLockDB DAVLock
+<Location />
+	Dav on
+</Location>
+EOF
+
+		if test "$LIB_HTTPD_SVN" != ""
+		then
+			rawsvnrepo="$LIB_HTTPD_ROOT_PATH/svnrepo"
+			svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn";
+
+			conf_load_module dav_svn_module mod_dav_svn.so
+			conf_write <<EOF
+<Location /svn>
+	DAV svn
+	SVNPath $rawsvnrepo
+</Location>
+EOF
+		fi
+	fi
+}
+
+start_httpd() {
+	test $# -eq 0 ||
+	error "error: not 0 parameters to start_httpd"
+
+	prepare_httpd
+
+	if test $HTTPD_VERSION_MAJOR -ge 2
+	then
+		"$LIB_HTTPD_PATH" -f "$LIB_HTTPD_ROOT_PATH"/httpd.conf -k start
+	else
+		start-stop-daemon --start \
+			--pidfile "$LIB_HTTPD_ROOT_PATH/httpd.pid" \
+			--exec "$LIB_HTTPD_PATH" \
+			-- -f "$LIB_HTTPD_ROOT_PATH"/httpd.conf
+	fi
+}
+
+stop_httpd() {
+	test $# -eq 0 ||
+	error "error: not 0 parameters to stop_httpd"
+
+	if test $HTTPD_VERSION_MAJOR -ge 2
+	then
+		"$LIB_HTTPD_PATH" -f "$LIB_HTTPD_ROOT_PATH"/httpd.conf -k stop
+	else
+		start-stop-daemon --stop \
+			--pidfile "$LIB_HTTPD_ROOT_PATH/httpd.pid"
+	fi
+}
diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh
new file mode 100644
index 0000000..9706f30
--- /dev/null
+++ b/t/t5540-http-push.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Clemens Buchacher <drizzd@xxxxxx>
+#
+
+test_description='test http-push
+
+This test runs various sanity checks on http-push.'
+
+. ./test-lib.sh
+
+ROOT_PATH=$PWD
+LIB_HTTPD_ROOT_PATH=$ROOT_PATH
+LIB_HTTPD_DAV=t
+
+. ../lib-httpd.sh
+
+if ! test -x "$LIB_HTTPD_PATH"
+then
+        test_expect_success "skipping http-push tests, no web server found at $LIB_HTTPD_PATH" :
+        test_done
+        exit
+fi
+
+test_expect_success 'setup web server' '
+	start_httpd
+'
+
+test_expect_success 'setup remote repository' '
+	cd "$ROOT_PATH" &&
+	mkdir test_repo &&
+	cd test_repo &&
+	git init &&
+	: >path1 &&
+	git add path1 &&
+	test_tick &&
+	git commit -m initial &&
+	cd - &&
+	git clone --bare test_repo test_repo.git &&
+	cd test_repo.git &&
+	git --bare update-server-info &&
+	chmod +x hooks/post-update
+'
+	
+test_expect_success 'clone remote repository' '
+	cd "$ROOT_PATH" &&
+	git clone $HTTPD_URL/test_repo.git test_repo_clone
+'
+
+if ! test -n "$HTTPD_VERSION" -a $HTTPD_VERSION_MAJOR -ge 2
+then
+	test_expect_success "skipping remaining http-push tests, at least Apache version 2 is required" :
+        test_done
+        exit
+fi
+
+test_expect_success 'push to remote repository' '
+	cd "$ROOT_PATH"/test_repo_clone &&
+	: >path2 &&
+	git add path2 &&
+	test_tick &&
+	git commit -m path2 &&
+	git push
+'
+
+test_expect_success 'create and delete remote branch' '
+	cd "$ROOT_PATH"/test_repo_clone &&
+	git checkout -b dev &&
+	: >path3 &&
+	git add path3 &&
+	test_tick &&
+	git commit -m dev &&
+	git push origin dev &&
+	git fetch &&
+	git push origin :dev &&
+	git branch -d -r origin/dev &&
+	git fetch &&
+	! git show-ref --verify refs/remotes/origin/dev
+'
+
+stop_httpd
+
+test_done
-- 
1.5.4.2.156.ge3c5

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux