2019-05-01 09:46:57 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-01-02 16:21:28 +00:00
|
|
|
#===============================================================================
|
|
|
|
#
|
|
|
|
# FILE: e-env-test.sh
|
|
|
|
#
|
|
|
|
# USAGE: must run only from dev/all-tests.sh
|
|
|
|
#
|
|
|
|
# DESCRIPTION: test BASHBOT_xxx variables working as expected
|
|
|
|
#
|
|
|
|
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
|
|
|
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
|
|
|
#
|
2021-06-03 12:21:40 +00:00
|
|
|
#### $$VERSION$$ v1.51-0-g6e66a28
|
2021-01-02 16:21:28 +00:00
|
|
|
#===============================================================================
|
2019-05-01 09:46:57 +00:00
|
|
|
|
|
|
|
# include common functions and definitions
|
|
|
|
# shellcheck source=test/ALL-tests.inc.sh
|
|
|
|
source "./ALL-tests.inc.sh"
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
#cd "${TESTDIR}" || exit 1
|
|
|
|
|
|
|
|
# source bashbot.sh function, uncomment if you want to test functions
|
|
|
|
# shellcheck source=./bashbot.sh
|
|
|
|
# source "\/bashbot.sh" source
|
|
|
|
|
|
|
|
# start writing your tests here ...
|
|
|
|
# test setting of env variables to different locations
|
|
|
|
|
|
|
|
export BASHBOT_ETC="${TESTDIR}/env/etc/bashbot"
|
|
|
|
export BASHBOT_VAR="${TESTDIR}/env/var/bashbot"
|
|
|
|
export BASHBOT_JSONSH="${TESTDIR}/env/local/bin/JSON.sh"
|
|
|
|
BASHBOT_BIN="${TESTDIR}/env/local/bin"
|
|
|
|
|
|
|
|
# create dirs
|
|
|
|
mkdir -p "${BASHBOT_ETC}" || exit 1
|
|
|
|
mkdir -p "${BASHBOT_VAR}" || exit 1
|
|
|
|
mkdir -p "${BASHBOT_BIN}" || exit 1
|
|
|
|
|
2020-06-23 14:35:50 +00:00
|
|
|
# cp bashbot files to new locations
|
2019-05-01 09:46:57 +00:00
|
|
|
set +f
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
|
|
|
|
set -f
|
2020-12-27 13:37:07 +00:00
|
|
|
cp -r "${TESTDIR}/bashbot.sh" "${TESTDIR}/modules" "${TESTDIR}/JSON.sh/JSON.sh" "${BASHBOT_BIN}" || exit 1
|
2019-05-01 09:46:57 +00:00
|
|
|
|
2020-06-29 09:13:25 +00:00
|
|
|
TESTFILES="${TOKENFILE} ${ACLFILE}"
|
2019-05-01 09:46:57 +00:00
|
|
|
|
|
|
|
|
2021-01-02 16:21:28 +00:00
|
|
|
printf "Check first run in ENVIRONMENT ...\n"
|
2021-01-01 18:25:25 +00:00
|
|
|
mkdir "${BASHBOT_VAR}/${DATADIR}"
|
2019-05-01 09:46:57 +00:00
|
|
|
|
|
|
|
# run bashbot first time with init
|
|
|
|
"${BASHBOT_BIN}/bashbot.sh" init >"${LOGFILE}" <<EOF
|
2021-01-05 11:06:22 +00:00
|
|
|
${TESTTOKEN}
|
2019-05-01 09:46:57 +00:00
|
|
|
nobody
|
|
|
|
botadmin
|
|
|
|
EOF
|
2021-01-02 16:21:28 +00:00
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-05-01 09:46:57 +00:00
|
|
|
|
2021-01-02 16:21:28 +00:00
|
|
|
printf "Check if files are placed in ENVIRONMENT ...\n"
|
2019-05-01 09:46:57 +00:00
|
|
|
if [ ! -f "${BASHBOT_JSONSH}" ]; then
|
2021-01-02 16:21:28 +00:00
|
|
|
printf "%s\n" "${NOSUCCESS} ${BASHBOT_JSONSH} missing!"
|
2019-05-01 09:46:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -d "${BASHBOT_VAR}/${DATADIR}" ]; then
|
2021-01-02 16:21:28 +00:00
|
|
|
printf "%s\n" "${NOSUCCESS} ${DATADIR} missing!"
|
2019-05-01 09:46:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -f "${BASHBOT_VAR}/${COUNTFILE}" ]; then
|
2021-01-02 16:21:28 +00:00
|
|
|
printf "%s\n" "${NOSUCCESS} ${BASHBOT_VAR}/${COUNTFILE} missing!"
|
2019-05-01 09:46:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-01-02 16:21:28 +00:00
|
|
|
printf " ... BASHBOT_VAR seems to work!\n"
|
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-05-01 09:46:57 +00:00
|
|
|
|
|
|
|
|
2020-06-23 14:35:50 +00:00
|
|
|
# compare files with reference files
|
2019-05-01 09:46:57 +00:00
|
|
|
export FAIL="0"
|
|
|
|
for file in ${TESTFILES}
|
|
|
|
do
|
|
|
|
ls -d "${BASHBOT_ETC}/${file}" >>"${LOGFILE}"
|
2021-01-02 16:21:28 +00:00
|
|
|
if ! diff -q "${BASHBOT_ETC}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}"; then printf "%s\n" "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; fi
|
2019-05-01 09:46:57 +00:00
|
|
|
|
|
|
|
done
|
|
|
|
|
2021-01-02 16:21:28 +00:00
|
|
|
printf " ... BASHBOT_ETC seems to work!\n"
|
|
|
|
printf "%s\n" "${SUCCESS}"
|