# !/usr/bin/env bash

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

set -euox pipefail

COMMAND_TO_TEST="vehicle/puffin/src/resources/scripts/collect_logs.sh"
BIN_DEPENDENCY="./bin/collect_logs"


setup_test(){
    mkdir driving --parents
    source ./vehicle/puffin/src/resources/scripts/mocks.sh
}

test_successful_script() {
    mock_zcore_safe_successful
    collect_logs(){
        echo mock collect_logs $@; return 0;
    }
    remote_command(){
        echo mock remote_command $@; return 0;
    }


    output="$(HOME="." source ${COMMAND_TO_TEST})"
    expected="mock zcore exiting successfully
--------- operator logs ------
mock collect_logs
--------- ai logs ------
mock remote_command collect_logs"

    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
test_early_exit_if_zcore_is_running_script
test_command_exists

