Break up test scripts
This commit is contained in:
18
makefile
18
makefile
@@ -10,26 +10,32 @@ BUILDDIRS = $(patsubst ./src/%, ./build/%, $(shell find ./src/ -type d))
|
|||||||
|
|
||||||
BINARY_NAME = server.out
|
BINARY_NAME = server.out
|
||||||
BINARY_OUT = ./build/${BINARY_NAME}
|
BINARY_OUT = ./build/${BINARY_NAME}
|
||||||
|
BINARY_OUT_BIN = ./bin/${BINARY}
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
./build/%.o: ./src/%.cpp
|
|
||||||
${CC} ${CFLAGS} -MMD -c $< -o $@
|
|
||||||
|
|
||||||
${BINARY_OUT}: directories ${OBJS}
|
${BINARY_OUT}: directories ${OBJS}
|
||||||
${CC} ${CFLAGS} ${OBJS} ${LFLAGS} -o $@
|
${CC} ${CFLAGS} ${OBJS} ${LFLAGS} -o $@
|
||||||
|
|
||||||
.PHONY: all clean check syntax directories
|
./build/%.o: ./src/%.cpp
|
||||||
|
${CC} ${CFLAGS} -MMD -c $< -o $@
|
||||||
|
|
||||||
|
${BINARY_OUT_BIN}: ${BINARY_OUT}
|
||||||
|
cp -u $^ $@
|
||||||
|
|
||||||
|
.PHONY: all clean check tests syntax directories
|
||||||
|
|
||||||
all: ${BINARY_OUT}
|
all: ${BINARY_OUT}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -r ./build/
|
-rm -r ./build/
|
||||||
|
|
||||||
check: ${BINARY_OUT}
|
check: ${BINARY_OUT_BIN}
|
||||||
cp -uv $^ ./bin/
|
|
||||||
cd ./bin/ && ./${BINARY_NAME}
|
cd ./bin/ && ./${BINARY_NAME}
|
||||||
|
|
||||||
|
tests: ${BINARY_OUT_BIN}
|
||||||
|
cd ./test/ && ./tests.sh
|
||||||
|
|
||||||
syntax: ${CPPS}
|
syntax: ${CPPS}
|
||||||
${CC} ${CFLAGS} -fsyntax-only $^
|
${CC} ${CFLAGS} -fsyntax-only $^
|
||||||
|
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
#!/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
|
|
||||||
8
test/startwebserver.sh
Executable file
8
test/startwebserver.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "Starting webserver..."
|
||||||
|
|
||||||
|
until pgrep "$SERVER"; do
|
||||||
|
cd "$SERVER_DIR" && ./$SERVER &
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
4
test/stopwebserver.sh
Executable file
4
test/stopwebserver.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "Stopping webserver..."
|
||||||
|
killall "$SERVER"
|
||||||
40
test/test_get.sh
Executable file
40
test/test_get.sh
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
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 for $1"
|
||||||
|
else
|
||||||
|
echo "FAILURE MD5 differs for $1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm $downloadedFile
|
||||||
|
else
|
||||||
|
echo "FAILURE Cannot GET $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function TestGET()
|
||||||
|
{
|
||||||
|
truthFile="$WWW_ROOT/$1"
|
||||||
|
getUrl="http://localhost:8080/$1"
|
||||||
|
|
||||||
|
TestGetContent $getUrl $truthFile
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "********"
|
||||||
|
echo "GET TEST"
|
||||||
|
echo "********"
|
||||||
|
TestGET "index.html"
|
||||||
|
TestGET "robedude.png"
|
||||||
|
TestGET "hope.jpg"
|
||||||
|
TestGET "nevada.mp3"
|
||||||
|
TestGET "index.css"
|
||||||
|
TestGET "test.js"
|
||||||
|
TestGET "subdir/index.html"
|
||||||
38
test/test_head.sh
Executable file
38
test/test_head.sh
Executable file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function TestGetHeader()
|
||||||
|
{
|
||||||
|
curlHeaderOutputFile="./temp"
|
||||||
|
if curl -I $1 --output $curlHeaderOutputFile 2> /dev/null; then
|
||||||
|
regexPattern="Content\-Type: $2"
|
||||||
|
headerContentType="$(egrep -o "$regexPattern" $curlHeaderOutputFile)"
|
||||||
|
if [ -n "$headerContentType" ]; then
|
||||||
|
echo "SUCCESS GET headers for $1 has correct MIME type"
|
||||||
|
else
|
||||||
|
echo "FAILURE GET headers for $1 contains bad MIME type (expected <Content-Type: $2> but got <$headerContentType>)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm $curlHeaderOutputFile
|
||||||
|
else
|
||||||
|
echo "FAILURE Cannot GET headers for $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function TestHEAD()
|
||||||
|
{
|
||||||
|
getUrl="http://localhost:8080/$1"
|
||||||
|
|
||||||
|
TestGetHeader $getUrl $2
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "*********"
|
||||||
|
echo "HEAD TEST"
|
||||||
|
echo "*********"
|
||||||
|
TestHEAD "index.html" 'text/html'
|
||||||
|
TestHEAD "robedude.png" 'image/png'
|
||||||
|
TestHEAD "hope.jpg" 'image/jpeg'
|
||||||
|
TestHEAD "nevada.mp3" 'audio/mpeg3'
|
||||||
|
TestHEAD "index.css" 'text/css'
|
||||||
|
TestHEAD "test.js" 'application/javascript'
|
||||||
|
TestHEAD "subdir/index.html" 'text/html'
|
||||||
12
test/tests.sh
Executable file
12
test/tests.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export SERVER="server.out"
|
||||||
|
export SERVER_DIR="../bin/"
|
||||||
|
export WWW_ROOT="../bin/www"
|
||||||
|
|
||||||
|
./startwebserver.sh
|
||||||
|
|
||||||
|
./test_head.sh
|
||||||
|
./test_get.sh
|
||||||
|
|
||||||
|
./stopwebserver.sh
|
||||||
Reference in New Issue
Block a user