#!/bin/bash

set -e

scripts_path=./$(dirname $0)
DIEGO_RELEASE_DIR=${DIEGO_RELEASE_DIR:-$(cd $scripts_path/.. && pwd)}

if [ "${SQL_FLAVOR}" = "mysql" ]; then
  echo "Running store-dependent test suites against a MySQL database..."
  DB_UNITS="./bbs/db/sqldb"
elif [ "${SQL_FLAVOR}" = "postgres" ]; then
  echo "Running store-dependent test suites against a Postgres database..."
  DB_UNITS="./bbs/db/sqldb"
else
  echo "Running store-dependent test suites against ETCD..."
  DB_UNITS="./bbs/db/etcd"
fi

ERROR_CODE=1

pushd $DIEGO_RELEASE_DIR/src/code.cloudfoundry.org/ > /dev/null
  ginkgo -r -keepGoing -p -trace -randomizeAllSpecs -progress --race \
    auctioneer/cmd/auctioneer \
    bbs/cmd/bbs \
    bbs/db/migrations \
    converger/cmd/converger \
    locket/cmd/locket \
    locket/db \
    rep/cmd/rep \
    cfdot/integration \
    rep/generator/internal \
    route-emitter/cmd/route-emitter \
    ${DB_UNITS}

  ERROR_CODE=$?
popd > /dev/null



exit $ERROR_CODE

