#!/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 GET $1"
		else
			echo "FAILURE GET 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 "ouroboros-by-kevin-macleod.mp3"
TestGET "file_example_MP4_480_1_5MG.mp4"
TestGET "index.css"
TestGET "test.js"
TestGET "subdir/index.html"