#!/bin/sh
#
# lua-http debian/tests/server-hello
#
# Test that runs server_hello.lua from the lua-http examples
# It replies with a "Hello world!" if the request is not a HEAD method.
#
# Author: Santiago Ruano Rincón <santiago@debian.org>

set -e

PORT=12345
HELLO_WORLD="Hello world!"

lua5.1 /usr/share/doc/lua-http/examples/server_hello.lua $PORT 2>&1 &
SERVER_PID=$!
trap "kill $SERVER_PID" 0 INT QUIT ABRT PIPE TERM
sleep 2
OUTPUT=`curl --silent http://localhost:$PORT`


# The server should return "Hello world!"
if [ ! "$OUTPUT" = "$HELLO_WORLD" ] ; then
    echo "Outcome: $OUTPUT"
    echo "Expected: $HELLO_WORLD"
    exit 1
fi
exit 0
