Integration test added
This commit is contained in:
83
test/integrationtest.sh
Executable file
83
test/integrationtest.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
serverBinary="server.out"
|
||||
serverWorkingDirectory="../bin"
|
||||
serverWwwRoot="$serverWorkingDirectory/www"
|
||||
|
||||
function KillServer()
|
||||
{
|
||||
echo "Stopping server..."
|
||||
killall "$serverBinary"
|
||||
}
|
||||
|
||||
function StartServer()
|
||||
{
|
||||
echo "Starting server..."
|
||||
oldPwd=$PWD
|
||||
until pgrep "$serverBinary"; do
|
||||
cd "$serverWorkingDirectory" && ./$serverBinary &
|
||||
sleep 2
|
||||
done
|
||||
cd "$oldPwd"
|
||||
}
|
||||
|
||||
function TestGetHeader()
|
||||
{
|
||||
curlHeaderOutputFile="./temp"
|
||||
if curl -I $1 --output $curlHeaderOutputFile 2> /dev/null; then
|
||||
|
||||
regexPattern="Content\-Type: $2"
|
||||
if egrep -o "$regexPattern" $curlHeaderOutputFile; then
|
||||
echo "SUCCESS GET headers for $1 has correct MIME type"
|
||||
else
|
||||
echo "FAILURE GET headers for $1 contains bad MIME type"
|
||||
echo "expected Content-Type: $2"
|
||||
echo "actual $(egrep -o \"$regexPattern\" $curlHeaderOutputFile)"
|
||||
fi
|
||||
|
||||
rm $curlHeaderOutputFile
|
||||
else
|
||||
echo "FAILURE Cannot GET headers for $1"
|
||||
fi
|
||||
}
|
||||
|
||||
function TestGetContent()
|
||||
{
|
||||
downloadedFile="./temp"
|
||||
if curl "$1" --output "$downloadedFile" 2> /dev/null; then
|
||||
expectedMd5="$(md5sum $2 | awk '{print $1}')"
|
||||
actualMd5="$(md5sum $downloadedFile | awk '{print $1}')"
|
||||
|
||||
if [ "$expectedMd5" == "$actualMd5" ]; then
|
||||
echo "SUCCESS GET request content matched for $1"
|
||||
else
|
||||
echo "FAILURE file MD5 differs for $1"
|
||||
echo "expected $truthMd5"
|
||||
echo "actual $actualMd5"
|
||||
fi
|
||||
|
||||
rm $downloadedFile
|
||||
else
|
||||
echo "FAILURE Cannot GET content for $1"
|
||||
fi
|
||||
}
|
||||
|
||||
function TestGET()
|
||||
{
|
||||
truthFile="$serverWwwRoot/$1"
|
||||
getUrl="http://localhost:8080/$1"
|
||||
|
||||
TestGetContent $getUrl $truthFile
|
||||
TestGetHeader $getUrl $2
|
||||
echo ""
|
||||
}
|
||||
|
||||
StartServer
|
||||
TestGET "index.html" 'text/html'
|
||||
TestGET "robedude.png" 'image/png'
|
||||
TestGET "hope.jpg" 'image/jpeg'
|
||||
TestGET "nevada.mp3" 'audio/mpeg3'
|
||||
TestGET "index.css" 'text/css'
|
||||
TestGET "test.js" 'application/javascript'
|
||||
TestGET "subdir/index.html" 'text/html'
|
||||
KillServer
|
||||
Reference in New Issue
Block a user