#!/bin/bash -l

set -ex

export PATH=/var/vcap/packages/rtr/bin:${PATH} # put the routing-api cli on the path
export PATH=/var/vcap/packages/cf-cli-8-linux/bin:${PATH} # put the cf cli on the path

ACCEPTANCE_BIN=/var/vcap/packages/acceptance_tests/bin

export CONFIG=/var/vcap/jobs/acceptance_tests/bin/config.json

mkdir -p /var/vcap/sys/log/acceptance_tests

EXITSTATUS=0
nodes=<%= properties.acceptance_tests.nodes %>
verbose=<%= properties.acceptance_tests.verbose ? "-v" : "" %>

"${ACCEPTANCE_BIN}/ginkgo" "${ACCEPTANCE_BIN}/http-routes.test" \
  -randomize-all $verbose -nodes=$nodes -keep-going || EXITSTATUS=$?

"${ACCEPTANCE_BIN}/ginkgo" "${ACCEPTANCE_BIN}/tcp-routing.test" \
  -randomize-all $verbose -nodes=$nodes -keep-going || EXITSTATUS=$?

echo "Acceptance Tests Complete; exit status: $EXITSTATUS"

for i in /var/vcap/sys/log/acceptance_tests/*.txt; do
  if [ -e "$i" ]; then
    mv $i $i.log # needed to make download-logs work
  fi
done

exit $EXITSTATUS
