#!/bin/bash
set -e

export LC_ALL=C.UTF-8
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 debian/tests/testdata.tar.xz "${AUTOPKGTEST_TMP}"
cd "${AUTOPKGTEST_TMP}"

tar -xf testdata.tar.xz

OUTPUT_FILE_1="test1"
OUTPUT_FILE_2="test2"

gunzip -c reads.fastq.gz | NanoFilt -q 8 -l 500 --headcrop 50 > "$OUTPUT_FILE_1"
# Double check and make sure file is actually generated and is non-zero size
if [ -s "$OUTPUT_FILE_1" ]; 
then
	echo "[1] PASS"
else
	echo "[1] FAIL"
	exit 1
fi

gunzip -c reads.fastq.gz | NanoFilt -q 7 --maxGC 0.75 --headcrop 75 | gzip > trimmed-reads.fastq.gz
echo "[2] PASS"

gunzip -c reads.fastq.gz | NanoFilt -q 6 -s sequencing_summary.txt > "$OUTPUT_FILE_2"
if [ -s "$OUTPUT_FILE_2" ];
then
	echo "[3] PASS"
else
	echo "[3] FAIL"
fi
