telegram-bot-bash/test/c-init-test.sh

57 lines
1.1 KiB
Bash
Raw Normal View History

2019-04-19 15:31:01 +00:00
#!/usr/bin/env bash
2019-04-20 19:09:36 +00:00
#### $$VERSION$$ 0.70-dev-18-g7512681
2019-04-19 15:31:01 +00:00
TESTME="$(basename "$0")"
2019-04-20 19:09:36 +00:00
DIRME="$(pwd)"
TESTDIR="$1"
LOGFILE="${TESTDIR}/${TESTME}.log"
REFDIR="${TESTME%.sh}"
TOKENFILE="token"
TESTTOKEN="bashbottestscript"
TESTFILES="${TOKENFILE} botacl count botadmin"
2019-04-19 17:24:30 +00:00
2019-04-19 15:31:01 +00:00
set -e
# let's fake failing test for now
echo "Running bashbot init"
echo "............................"
# change to test env
2019-04-20 19:09:36 +00:00
[ "${TESTDIR}" = "" ] && echo "not called from testsuite, exit" && exit
2019-04-19 15:31:01 +00:00
unset IFS; set -f
# run bashbot first time with init
export TERM=""
2019-04-20 19:09:36 +00:00
"${TESTDIR}/bashbot.sh" init >"${LOGFILE}" <<EOF
2019-04-19 17:24:30 +00:00
$TESTTOKEN
2019-04-19 15:31:01 +00:00
nobody
botadmin
EOF
2019-04-19 17:24:30 +00:00
echo "OK"
2019-04-20 19:09:36 +00:00
# compare files with refrence files
2019-04-19 17:24:30 +00:00
echo "Check check new files ..."
2019-04-20 19:09:36 +00:00
for file in ${TESTFILES}
2019-04-19 17:24:30 +00:00
do
2019-04-20 19:09:36 +00:00
ls -d "${TESTDIR}/${file}" >>"${LOGFILE}"
diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}"
2019-04-19 17:24:30 +00:00
done
echo "OK"
2019-04-20 14:26:16 +00:00
echo "Test Sourcing of bashbot.sh ..."
trap exit 1 EXIT
2019-04-20 19:09:36 +00:00
cd "${TESTDIR}" || exit
2019-04-20 14:26:16 +00:00
# shellcheck source=./bashbot.sh
2019-04-20 19:09:36 +00:00
source "${TESTDIR}/bashbot.sh" source
2019-04-20 14:26:16 +00:00
trap '' EXIT
2019-04-20 19:09:36 +00:00
cd "${DIRME}" || exit 1
echo "Test bashbot.sh count"
cp "${REFDIR}/count.test" "${TESTDIR}/count"
"${TESTDIR}/bashbot.sh" count