#!/bin/csh
# Usage: do_test filepath test#
#  e.g.: do_test docs/1K.txt 1
#  e.g.: do_test docs/10K.txt 2
#
# filepath is relative to where the test is run from.

set tmpfile=/tmp/do_test.out

if ($#argv != 3) then
  echo "Usage: $0 restart filepath test#"
  exit 1
endif

set restart_server=$1
set filepath=$2
set testnum=$3

set PORT=6800
set DOCS=docs
set URL="http://localhost:$PORT/$filepath"

if ($restart_server) then
  ./userver >& SERVER-OUT.$testnum &
  sleep 2
endif

GET $URL > OUT.$testnum
diff $filepath OUT.$testnum > $tmpfile
set x=$status

# echo "x=$x"
if ($x == "0") then
  echo "Test $testnum passed"
else
  echo "Failed to get $URL properly on test = $testnum"
  # cat $tmpfile
  exit 1
endif

if ($restart_server) then
  pkill userver >& $tmpfile
  set x=$status
  sleep 2
endif

exit 0
