replace unusual command by id, remove phyton tests

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-16 11:23:27 +02:00
parent 412173cf85
commit d01addf0a9
4 changed files with 25 additions and 26 deletions

View File

@ -12,7 +12,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.80-dev2-15-geb0cde5 #### $$VERSION$$ v0.80-dev2-20-g412173c
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -155,15 +155,16 @@ get_file() {
[ "$1" = "" ] && return [ "$1" = "" ] && return
local JSON='"file_id": '"${1}" local JSON='"file_id": '"${1}"
sendJson "" "${JSON}" "${GETFILE_URL}" sendJson "" "${JSON}" "${GETFILE_URL}"
echo "${URL}/$(echo "${res}" | jsonGetString '"result","file_path"')" jsonGetString <<< "${URL}/""${res}" '"result","file_path"'
} }
# usage: sendJson "chat" "JSON" "URL" # curl is preffered, but may not availible on ebedded systems
if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
# simple curl or wget call, output to stdout # simple curl or wget call, output to stdout
getJson(){ getJson(){
curl -sL "$1" curl -sL "$1"
} }
# usage: sendJson "chat" "JSON" "URL"
sendJson(){ sendJson(){
local chat=""; local chat="";
[ "${1}" != "" ] && chat='"chat_id":'"${1}"',' [ "${1}" != "" ] && chat='"chat_id":'"${1}"','
@ -175,12 +176,13 @@ if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
else else
# simple curl or wget call outputs result to stdout # simple curl or wget call outputs result to stdout
getJson(){ getJson(){
wegt -q -O- "$1" wget -qO - "$1"
} }
# usage: sendJson "chat" "JSON" "URL"
sendJson(){ sendJson(){
local chat=""; local chat="";
[ "${1}" != "" ] && chat='"chat_id":'"${1}"',' [ "${1}" != "" ] && chat='"chat_id":'"${1}"','
res="$(wget -q -O- --post-data='{'"${chat} $2"'}' \ res="$(wget -qO - --post-data='{'"${chat} $2"'}' \
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )" --header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )"
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")" BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")" BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")"
@ -382,7 +384,7 @@ bot_init() {
echo -n "Enter User to run basbot [$RUNUSER]: " echo -n "Enter User to run basbot [$RUNUSER]: "
read -r TOUSER read -r TOUSER
[ "$TOUSER" = "" ] && TOUSER="$RUNUSER" [ "$TOUSER" = "" ] && TOUSER="$RUNUSER"
if ! compgen -u "$TOUSER" >/dev/null 2>&1; then if ! id "$TOUSER" >/dev/null 2>&1; then
echo -e "${RED}User \"$TOUSER\" not found!${NC}" echo -e "${RED}User \"$TOUSER\" not found!${NC}"
exit 3 exit 3
else else

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.80-dev2-1-g0b36bc5 #### $$VERSION$$ v0.80-dev2-20-g412173c
# common variables # common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
@ -11,12 +11,13 @@ export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
TESTNAME="${REFDIR//-/ }" TESTNAME="${REFDIR//-/ }"
# common filenames # common filenames
export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR JSONSHFILE
TOKENFILE="token" TOKENFILE="token"
ACLFILE="botacl" ACLFILE="botacl"
COUNTFILE="count" COUNTFILE="count"
ADMINFILE="botadmin" ADMINFILE="botadmin"
DATADIR="data-bot-bash" DATADIR="data-bot-bash"
JSONSHFILE="JSON.sh/JSON.sh"
# SUCCESS NOSUCCES # SUCCESS NOSUCCES
export SUCCESS NOSUCCESS export SUCCESS NOSUCCESS

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.80-dev2-7-g92f022d #### $$VERSION$$ v0.80-dev2-20-g412173c
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -24,16 +24,18 @@ export FAIL="0"
for file in ${TESTFILES} for file in ${TESTFILES}
do do
ls -d "${TESTDIR}/${file}" >>"${LOGFILE}" ls -d "${TESTDIR}/${file}" >>"${LOGFILE}"
if ! diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}"; then echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; fi diff -q "${TESTDIR}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}" || { echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; }
done done
[ "${FAIL}" != "0" ] && exit "${FAIL}" [ "${FAIL}" != "0" ] && exit "${FAIL}"
echo "${SUCCESS}" echo "${SUCCESS}"
echo "Test Sourcing of bashbot.sh ..."
trap exit 1 EXIT trap exit 1 EXIT
cd "${TESTDIR}" || exit cd "${TESTDIR}" || exit
echo "Test if $JSONSHFILE exists ..."
[ ! -x "$JSONSHFILE" ] && { echo "${NOSUCCESS} Fail diff ${file}!"; exit 1; }
echo "Test Sourcing of bashbot.sh ..."
# shellcheck source=./bashbot.sh # shellcheck source=./bashbot.sh
source "${TESTDIR}/bashbot.sh" source source "${TESTDIR}/bashbot.sh" source
source "${TESTDIR}/commands.sh" source source "${TESTDIR}/commands.sh" source

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v0.80-dev2-7-g92f022d #### $$VERSION$$ v0.80-dev2-20-g412173c
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -23,20 +23,14 @@ get_file() {
export UPDATE export UPDATE
UPDATE="$(cat "${INPUTFILE}")" UPDATE="$(cat "${INPUTFILE}")"
# run process_message with and without phyton # run process_message
echo "Check process_message ..." echo "Check process_message ..."
for i in 1 2 set -x
do { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
[ "${i}" = "1" ] && ! which python >/dev/null 2>&1 && continue
[ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE
[ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes"
set -x
{ process_message "0"; set +x; } >>"${LOGFILE}" 2>&1;
# output processed input # output processed input
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}" print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" "VENUE" >"${OUTPUTFILE}"
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
echo "${SUCCESS}" echo "${SUCCESS}"
done
cd "${DIRME}" || exit 1 cd "${DIRME}" || exit 1