#!/bin/bash
set -e

pkg=virulencefinder

if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

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

cd "${AUTOPKGTEST_TMP}"
gunzip -r *

# upstream test script is a bit broken
virulencefinder.py -i test.fsa -o . -p database -mp blastn -x -q
file=results_tab.tsv
if [ ! -s $file ] ; then
   echo "Result file $file is missing."
   echo "TEST FAILED"
   exit 1
fi
DIFF=$(diff $file test_results.tsv)
if [ "$DIFF" = "" ] ; then
   echo "TEST SUCCEEDED"
else
   echo "TEST FAILED"
fi
