# !/usr/bin/env bash

##
# NOTE: This test is designed to run in bazel!
##

set -euox pipefail

COMMAND_TO_TEST="vehicle/puffin/src/resources/scripts/get_ip_address.sh"
TMP_STOP_LOGGER="/tmp/"$$

setup_test(){
    mock_script
}

mock_script(){
    cat ${COMMAND_TO_TEST} > ${TMP_STOP_LOGGER}
    echo "echo 'mock stop_bootstrap_logger exiting successfully';" > ${COMMAND_TO_TEST}
    chmod +x ${COMMAND_TO_TEST}

    trap "
    cat ${TMP_STOP_LOGGER} > ${COMMAND_TO_TEST} # Restore command
    " EXIT
}


test_successful_script() {
    output="$(HOME="." source ${COMMAND_TO_TEST})"
    expected="mock stop_bootstrap_logger exiting successfully"

    echo "output:${output}"
    if [ "${output}" == "${expected}" ]; then
        echo " Script correctly exited normal execution."
    else
        echo " Script failed execution."
        exit 1
    fi
}

setup_test
test_successful_script

