#!/bin/bash
source ../test_common.sh
set_test_name "${BASH_SOURCE[0]}"

testfun() {
    [[ -f orthomapper.sh ]] || { echo "error: setup.sh not executed - missing orthomapper.sh"; return 255; }

    # 1. check setup
    ./orthomapper.sh CHECK || { echo "error: failed check!"; return 255; }

    # 2. download a sample fasta
    download_fasta unknown.fs || return 255

    # 3. import sample fasta (format "<name>:<filename>")
    local name="bacunk"
    local nodeid=91347
    local run_label="busco_auto_$name"
    ./orthomapper.sh IMPORT "${name}:refs/unknown.fs" || { echo "error: failed importing primate.fs to user"; return 255; }

    # make sure there are no busco results
    rm -Rf busco/$name
    
    # 6. start BUSCO at enterobacterales (NCBI taxid 91347) node
    local ec=0
    ./orthomapper.sh RUN taxid=$name mode=busco label=$run_label go
    if [[ $? -eq 0 ]]; then
        check_busco_result "$run_label" "$nodeid"
        ec=$?
    fi
    return $ec
}
run_test
exit $?

