#!/usr/bin/env bash
set -xeuo pipefail

source vehicle/common/environment/robot_name/robot_name.sh

[ "$ZOOX_ROBOT_NAME_FILE" == /etc/robot_name ]

ZOOX_ROBOT_NAME_FILE="$TEST_TMPDIR/robot_name"

# File does not exist; variable is empty.
rm --force "$ZOOX_ROBOT_NAME_FILE"
ZOOX_ROBOT_NAME=
! robot_name

# File exists but is empty; variable is empty.
echo > "$ZOOX_ROBOT_NAME_FILE"
ZOOX_ROBOT_NAME=
! robot_name

# File does not exist; variable is set.
rm --force "$ZOOX_ROBOT_NAME_FILE"
ZOOX_ROBOT_NAME=kitt_01
[ "$(robot_name)" == kitt_01 ]

# File exists but is empty; variable is set.
echo > "$ZOOX_ROBOT_NAME_FILE"
ZOOX_ROBOT_NAME=kitt_01
! robot_name

# File exists and is non-empty; variable is empty.
echo kitt_01 > "$ZOOX_ROBOT_NAME_FILE"
ZOOX_ROBOT_NAME=
[ "$(robot_name)" == kitt_01 ]

# File exists and is non-empty; variable is set.
echo kitt_01 > "$ZOOX_ROBOT_NAME_FILE"
ZOOX_ROBOT_NAME=kitt_01
! robot_name
