2019-04-26 12:41:49 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-01-02 15:39:33 +00:00
|
|
|
#===============================================================================
|
|
|
|
#
|
|
|
|
# FILE: d-send_message-test.sh
|
|
|
|
#
|
|
|
|
# USAGE: must run only from dev/all-tests.sh
|
|
|
|
#
|
|
|
|
# DESCRIPTION: test sending messages
|
|
|
|
#
|
|
|
|
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
|
|
|
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
|
|
|
#
|
2021-03-10 07:39:17 +00:00
|
|
|
#### $$VERSION$$ v1.5-0-g8adca9b
|
2021-01-02 15:39:33 +00:00
|
|
|
#===============================================================================
|
2019-04-26 12:41:49 +00:00
|
|
|
|
|
|
|
# include common functions and definitions
|
|
|
|
# shellcheck source=test/ALL-tests.inc.sh
|
|
|
|
source "./ALL-tests.inc.sh"
|
|
|
|
|
|
|
|
set -e
|
2019-05-13 09:24:42 +00:00
|
|
|
set +f
|
2019-04-26 12:41:49 +00:00
|
|
|
|
|
|
|
cd "${TESTDIR}" || exit 1
|
|
|
|
|
|
|
|
# source bashbot.sh function, uncomment if you want to test functions
|
|
|
|
# shellcheck source=./bashbot.sh
|
|
|
|
source "${TESTDIR}/bashbot.sh" source
|
2019-05-13 09:24:42 +00:00
|
|
|
# shellcheck source=./bashbot.sh
|
|
|
|
source "${TESTDIR}/commands.sh" source
|
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
_is_function send_message || printf "Send Message not found!\n"
|
2019-04-26 12:41:49 +00:00
|
|
|
|
|
|
|
# start writing your tests here ...
|
|
|
|
|
|
|
|
# over write sendJson to output parameter only
|
2019-05-13 09:24:42 +00:00
|
|
|
sendEmpty() {
|
2021-01-05 15:17:34 +00:00
|
|
|
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "$1" "$2" "$3"
|
2019-05-13 09:24:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 12:41:49 +00:00
|
|
|
sendJson() {
|
2021-01-05 15:17:34 +00:00
|
|
|
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "$1" "$2" "$3"
|
2019-04-26 12:41:49 +00:00
|
|
|
}
|
2019-05-20 15:26:21 +00:00
|
|
|
sendUpload() {
|
|
|
|
#JSON:"document":"/tmp/allowed/this_is_my.doc","caption":"Text plus absolute file will appear in chat""
|
2021-01-05 15:17:34 +00:00
|
|
|
printf 'chat:%s\tJSON:"%s":"%s","caption":"%s"\nURL:%s\n\n' "$1" "$2" "$3" "$5" "$4"
|
2019-05-20 15:26:21 +00:00
|
|
|
}
|
2019-04-26 12:41:49 +00:00
|
|
|
|
|
|
|
# send text input to send_message
|
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " Send line ..."
|
2019-05-13 09:24:42 +00:00
|
|
|
|
2019-05-20 13:43:37 +00:00
|
|
|
# create dummy files for upload
|
|
|
|
ALLOW='/tmp/allowed'
|
2021-01-05 11:06:22 +00:00
|
|
|
FILE_REGEX="${ALLOW}/.*"
|
|
|
|
[ -d "${ALLOW}" ] || mkdir "${ALLOW}"
|
|
|
|
touch "${ALLOW}/this_is_my.gif" "${ALLOW}/this_is_my.doc"
|
|
|
|
touch "${DATADIR}/this_is_my.gif" "${DATADIR}/this_is_my.doc"
|
2019-05-20 13:43:37 +00:00
|
|
|
|
2019-05-13 09:24:42 +00:00
|
|
|
while read -r line ; do
|
2020-12-28 14:03:53 +00:00
|
|
|
set -x; set +e
|
2021-01-05 11:06:22 +00:00
|
|
|
send_message "123456" "${line}" >>"${OUTPUTFILE}"
|
2020-12-28 14:03:53 +00:00
|
|
|
set +x; set -e
|
2021-01-02 15:39:33 +00:00
|
|
|
printf "."
|
2019-05-20 13:43:37 +00:00
|
|
|
done < "${INPUTFILE}" 2>>"${LOGFILE}"
|
2021-01-05 11:06:22 +00:00
|
|
|
[ -d "${ALLOW}" ] && rm -rf "${ALLOW}"
|
2019-05-20 13:43:37 +00:00
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " done.\n"
|
2019-04-26 12:41:49 +00:00
|
|
|
|
2020-06-10 16:07:12 +00:00
|
|
|
{ compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1; } | cat -v
|
2020-06-01 13:04:37 +00:00
|
|
|
rm -f "${REFFILE}.sort"
|
|
|
|
|
2021-01-02 15:39:33 +00:00
|
|
|
printf " ... all \"send_message\" functions seems to work as expected.\n"
|
|
|
|
|
|
|
|
printf "%s\n" "${SUCCESS}"
|
2019-04-26 12:41:49 +00:00
|
|
|
|
|
|
|
|