#!/bin/bash
set -e

pkg=resfinder

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"
mkdir -p db_resfinder
cp -a /usr/share/resfinder/db/* db_resfinder
find -name '*.gz' -exec gunzip '{}' ';'

# Move data to deprecated dir as functional tests seek relative path
mv data deprecated/

echo "Indexing files as needed"
cd db_resfinder
python3 INSTALL.py 2> /dev/null
cd ..

cd db_pointfinder
python3 INSTALL.py 2> /dev/null
cd ..

echo "Running tests"
python3 deprecated/functional_tests.py \
	-db_res db_resfinder \
	-db_point db_pointfinder \
	-b /usr/bin/blastn \
	-k /usr/bin/kma

echo "Cleanup"
rm -rf db_*

echo "PASS"
