summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-09-10 12:53:25 +0200
committerMichael Adam <obnox@samba.org>2009-09-10 12:53:25 +0200
commit408c781d14377faf1e98e0eebdd8724844debeac (patch)
treebcc99d8775b877d1bb2e297035b517b20ddb82e6
parentdfa1763af9d8d92bf4a66aca7e86bb403868fc28 (diff)
downloadtinyproxy-408c781d14377faf1e98e0eebdd8724844debeac.tar.gz
tinyproxy-408c781d14377faf1e98e0eebdd8724844debeac.zip
tests: restructure run_tests into functions to make main flow clearer.
Also prepare for modularizing the testsuite. Michael
Diffstat (limited to '')
-rwxr-xr-xtests/scripts/run_tests.sh169
1 files changed, 104 insertions, 65 deletions
diff --git a/tests/scripts/run_tests.sh b/tests/scripts/run_tests.sh
index 281b099..00ff32c 100755
--- a/tests/scripts/run_tests.sh
+++ b/tests/scripts/run_tests.sh
@@ -22,54 +22,53 @@ SCRIPTS_DIR=$(pwd)/$(dirname $0)
BASEDIR=$SCRIPTS_DIR/../..
TESTS_DIR=$SCRIPTS_DIR/..
TESTENV_DIR=$TESTS_DIR/env
+LOG_DIR=$TESTENV_DIR/var/log
TINYPROXY_IP=127.0.0.2
TINYPROXY_PORT=12321
TINYPROXY_USER=$USER
TINYPROXY_PID_DIR=$TESTENV_DIR/var/run/tinyproxy
TINYPROXY_PID_FILE=$TINYPROXY_PID_DIR/tinyproxy.pid
-LOG_DIR=$TESTENV_DIR/var/log
TINYPROXY_LOG_DIR=$LOG_DIR
TINYPROXY_DATA_DIR=$TESTENV_DIR/usr/share/tinyproxy
TINYPROXY_CONF_DIR=$TESTENV_DIR/etc
TINYPROXY_CONF_FILE=$TINYPROXY_CONF_DIR/tinyproxy.conf
+TINYPROXY_STDERR_LOG=$TINYPROXY_LOG_DIR/tinyproxy.stderr.log
+TINYPROXY_BIN=$BASEDIR/src/tinyproxy
WEBSERVER_IP=127.0.0.3
WEBSERVER_PORT=32123
WEBSERVER_PID_DIR=$TESTENV_DIR/var/run/webserver
WEBSERVER_PID_FILE=$WEBSERVER_PID_DIR/webserver.pid
WEBSERVER_LOG_DIR=$TESTENV_DIR/var/log/webserver
-
-TINYPROXY_STDERR_LOG=$TINYPROXY_LOG_DIR/tinyproxy.stderr.log
-WEBCLIENT_LOG=$LOG_DIR/webclient.log
-
WEBSERVER_BIN_FILE=webserver.pl
WEBSERVER_BIN=$SCRIPTS_DIR/$WEBSERVER_BIN_FILE
-WEBCLIENT_BIN=$SCRIPTS_DIR/webclient.pl
-TINYPROXY_BIN=$BASEDIR/src/tinyproxy
-STAMP=$(date +%Y%m%d-%H:%M:%S)
+WEBCLIENT_LOG=$LOG_DIR/webclient.log
+WEBCLIENT_BIN=$SCRIPTS_DIR/webclient.pl
-if test -e $TESTENV_DIR ; then
- TESTENV_DIR_OLD=$TESTENV_DIR.old
- if test -e $TESTENV_DIR_OLD ; then
- rm -rf $TESTENV_DIR_OLD
+provision_initial() {
+ if test -e $TESTENV_DIR ; then
+ TESTENV_DIR_OLD=$TESTENV_DIR.old
+ if test -e $TESTENV_DIR_OLD ; then
+ rm -rf $TESTENV_DIR_OLD
+ fi
+ mv $TESTENV_DIR $TESTENV_DIR.old
fi
- mv $TESTENV_DIR $TESTENV_DIR.old
-fi
-mkdir -p $TINYPROXY_DATA_DIR
-cp $BASEDIR/doc/default.html $TINYPROXY_DATA_DIR
-cp $BASEDIR/doc/debug.html $TINYPROXY_DATA_DIR
-cp $BASEDIR/doc/stats.html $TINYPROXY_DATA_DIR
-mkdir -p $TINYPROXY_PID_DIR
-mkdir -p $TINYPROXY_LOG_DIR
-mkdir -p $TINYPROXY_CONF_DIR
+ mkdir -p $LOG_DIR
+}
-mkdir -p $WEBSERVER_PID_DIR
-mkdir -p $WEBSERVER_LOG_DIR
+provision_tinyproxy() {
+ mkdir -p $TINYPROXY_DATA_DIR
+ cp $BASEDIR/doc/default.html $TINYPROXY_DATA_DIR
+ cp $BASEDIR/doc/debug.html $TINYPROXY_DATA_DIR
+ cp $BASEDIR/doc/stats.html $TINYPROXY_DATA_DIR
+ mkdir -p $TINYPROXY_PID_DIR
+ mkdir -p $TINYPROXY_LOG_DIR
+ mkdir -p $TINYPROXY_CONF_DIR
-cat >>$TINYPROXY_CONF_FILE<<EOF
+ cat >>$TINYPROXY_CONF_FILE<<EOF
User $TINYPROXY_USER
#Group $TINYPROXY_GROUP
Port $TINYPROXY_PORT
@@ -91,59 +90,99 @@ ViaProxyName "tinyproxy"
ConnectPort 443
ConnectPort 563
EOF
+}
+
+start_tinyproxy() {
+ echo -n "starting tinyproxy..."
+ $TINYPROXY_BIN -c $TINYPROXY_CONF_FILE 2> $TINYPROXY_STDERR_LOG
+ echo " done"
+}
+
+stop_tinyproxy() {
+ echo -n "killing tinyproxy..."
+ kill $(cat $TINYPROXY_PID_FILE)
+ if test "x$?" = "x0" ; then
+ echo " ok"
+ else
+ echo " error"
+ fi
+}
+
+provision_webserver() {
+ mkdir -p $WEBSERVER_PID_DIR
+ mkdir -p $WEBSERVER_LOG_DIR
+}
+
+start_webserver() {
+ echo -n "starting web server..."
+ $WEBSERVER_BIN --port $WEBSERVER_PORT --log-dir $WEBSERVER_LOG_DIR --pid-file $WEBSERVER_PID_FILE
+ echo " done"
+}
+
+stop_webserver() {
+ echo -n "killing webserver..."
+ kill $(cat $WEBSERVER_PID_FILE)
+ if test "x$?" = "x0" ; then
+ echo " ok"
+ else
+ echo " error"
+ fi
+}
+
+wait_for_some_seconds() {
+ SECONDS=$1
+ if test "x$SECONDS" = "x" ; then
+ SECONDS=1
+ fi
+
+ echo -n "waiting for $SECONDS seconds."
+
+ COUNT=0
+ while test $COUNT -lt $SECONDS ; do
+ sleep 1
+ echo -n "."
+ COUNT=$(($COUNT + 1))
+ done
+ echo " done"
+}
+
+run_basic_webclient_request() {
+ $WEBCLIENT_BIN $1 $2 >> $WEBCLIENT_LOG 2>&1
+ WEBCLIENT_EXIT_CODE=$?
+ if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
+ echo " ok"
+ else
+ echo "ERROR ($EBCLIENT_EXIT_CODE)"
+ echo "webclient output:"
+ cat $WEBCLIENT_LOG
+ fi
+}
-echo -n "starting web server..."
-$WEBSERVER_BIN --port $WEBSERVER_PORT --log-dir $WEBSERVER_LOG_DIR --pid-file $WEBSERVER_PID_FILE
-echo " done"
+# "main"
-echo -n "starting tinyproxy..."
-$TINYPROXY_BIN -c $TINYPROXY_CONF_FILE 2> $TINYPROXY_STDERR_LOG
-echo " done"
+provision_initial
+provision_tinyproxy
+provision_webserver
-echo -n "waiting for 3 seconds."
-sleep 1
-echo -n "."
-sleep 1
-echo -n "."
-sleep 1
-echo -n "."
-echo " done"
+start_webserver
+start_tinyproxy
+
+wait_for_some_seconds 3
echo -n "checking direct connection to web server..."
-$WEBCLIENT_BIN $WEBSERVER_IP:$WEBSERVER_PORT / >> $WEBCLIENT_LOG 2>&1
-WEBCLIENT_EXIT_CODE=$?
-if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
- echo " ok"
-else
- echo "ERROR ($EBCLIENT_EXIT_CODE)"
- echo "webclient output:"
- cat $WEBCLIENT_LOG
-fi
+run_basic_webclient_request "$WEBSERVER_IP:$WEBSERVER_PORT" /
echo -n "testing connection through tinyproxy..."
-$WEBCLIENT_BIN $TINYPROXY_IP:$TINYPROXY_PORT http://$WEBSERVER_IP:$WEBSERVER_PORT/ >> $WEBCLIENT_LOG 2>&1
-WEBCLIENT_EXIT_CODE=$?
-if test "x$WEBCLIENT_EXIT_CODE" = "x0" ; then
- echo " ok"
-else
- echo "ERROR ($WEBCLIENT_EXIT_CODE)"
- echo "webclient output:"
- cat $WEBCLIENT_LOG
-fi
+run_basic_webclient_request "$TINYPROXY_IP:$TINYPROXY_PORT" "http://$WEBSERVER_IP:$WEBSERVER_PORT/"
+echo "You can continue using the webserver and tinyproxy."
echo -n "hit <enter> to stop the servers and exit: "
read READ
-echo -n "killing tinyproxy..."
-kill $(cat $TINYPROXY_PID_FILE)
-if test "x$?" = "x0" ; then echo "ok" ; else echo "error" ; fi
-
-echo -n "killing webserver..."
-# too crude still, need pid file handling for webserver:
-kill $(cat $WEBSERVER_PID_FILE)
-if test "x$?" = "x0" ; then echo "ok" ; else echo "error" ; fi
+stop_tinyproxy
+stop_webserver
-echo $0: done
+echo "done"
exit 0