# !/usr/bin/env bash

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

set -euox pipefail

COMMAND_TO_TEST="vehicle/puffin/src/resources/scripts/puffin_git_log.sh"

setup_test(){
    mkdir driving --parents
}

test_successful_script() {
    ssh(){
        echo mock ssh $@; return 0;
    }

    git(){
        echo mock git $@; return 0;
    }

    gnome-screenshot(){
        echo mock gnome-screenshot $@; return 0;
    }

    output="$(HOME="." source ${COMMAND_TO_TEST})"
    expected="
+----------------------- OPERATOR DRIVING SOFTWARE --------------------------+
mock git --no-pager log --decorate=short --pretty=oneline -n1

+------------------------ MAIN-AI DRIVING SOFTWARE --------------------------+
mock ssh main-ai cd driving; git --no-pager log --decorate=short --pretty=oneline -n1
mock gnome-screenshot"

    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
