#!/usr/bin/env bash

# The idea with this test is that there should be a bin
# present that the launch script can call. We want to verify
# that calling the launch script executes that bin.
set -euox pipefail

PROGRAM_TO_TEST="vehicle/puffin/launch.sh"


setup_test(){
    # turn the bin into a shell script that exits successfully.
    BIN_FILE=vehicle/puffin/*AppImage
    rm ${BIN_FILE}
    echo "
#!/usr/bin/env bash

set -euo pipefail

echo  \"puffin called\"
exit 0;
    " > ${BIN_FILE}
    chmod +x ${BIN_FILE}

    # mock rm
    rm() {
        exit 0;
    }

    # mock cp
    cp() {
        exit 0;
    }
}

test_successful_script() {

    if HOME="." source ${PROGRAM_TO_TEST} > /dev/null; then
        echo " Script correctly exited normal execution."
    else
        echo " Script failed execution."
        exit 1
    fi
}

setup_test
test_successful_script
