From 2dafbd9d63a454b4bbeac437ebd5bd740270ae1e Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 27 Jun 2020 18:31:35 +0200 Subject: [PATCH] adjust tests to changed behavior --- test/ALL-tests.inc.sh | 6 +++--- test/c-init-test/botadmin | 1 - test/c-init-test/botconfig.jssh | 3 +++ test/c-init-test/token | 1 - test/d-process_message-test.sh | 3 ++- .../d-process_message-test.result | 3 +-- .../d-send_message-test.result | 15 +++------------ test/d-user_is-test.sh | 10 +++++++--- 8 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 test/c-init-test/botadmin create mode 100644 test/c-init-test/botconfig.jssh delete mode 100644 test/c-init-test/token diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index 3ef079b..986805c 100644 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.98-pre2-0-ga597303 +#### $$VERSION$$ v0.98-pre2-8-ga656533 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME @@ -12,11 +12,11 @@ export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME # common filenames export TOKENFILE ACLFILE COUNTFILE BLOCKEDFILE ADMINFILE DATADIR JSONSHFILE - TOKENFILE="token" + TOKENFILE="botconfig.jssh" ACLFILE="botacl" COUNTFILE="count.jssh" BLOCKEDFILE="blocked.jssh" - ADMINFILE="botadmin" + ADMINFILE="botconfig.jssh" DATADIR="data-bot-bash" JSONSHFILE="JSON.sh/JSON.sh" diff --git a/test/c-init-test/botadmin b/test/c-init-test/botadmin deleted file mode 100644 index a1e2647..0000000 --- a/test/c-init-test/botadmin +++ /dev/null @@ -1 +0,0 @@ -? diff --git a/test/c-init-test/botconfig.jssh b/test/c-init-test/botconfig.jssh new file mode 100644 index 0000000..1585280 --- /dev/null +++ b/test/c-init-test/botconfig.jssh @@ -0,0 +1,3 @@ +["bot_config_key"] "config_key_value" +["bottoken"] "123456789:BASHBOTTESTSCRIPTbashbottestscript_" +["botadmin"] "?" diff --git a/test/c-init-test/token b/test/c-init-test/token deleted file mode 100644 index 006890a..0000000 --- a/test/c-init-test/token +++ /dev/null @@ -1 +0,0 @@ -123456789:BASHBOTTESTSCRIPTbashbottestscript_ diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 55728dd..7021f0c 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.98-pre2-0-ga597303 +#### $$VERSION$$ v0.98-pre2-8-ga656533 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -29,6 +29,7 @@ source <( printf 'UPD=( %s )' "$(sed <<<"${UPDATE}" -E -e 's/\t/=/g' -e 's/=(tru echo "Check process_message ..." set -x { process_message "0"; set +x; } >>"${LOGFILE}" 2>&1; +echo "Compare results" USER[ID]="123456789" CHAT[ID]="123456789" diff --git a/test/d-process_message-test/d-process_message-test.result b/test/d-process_message-test/d-process_message-test.result index 7fbedaf..6aa75b2 100644 --- a/test/d-process_message-test/d-process_message-test.result +++ b/test/d-process_message-test/d-process_message-test.result @@ -3,7 +3,6 @@ USER: ID 123456789 USER: LAST_NAME M USER: USERNAME Gnadelwartz CHAT: ALL_ADMIN -CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS CHAT: FIRST_NAME Test CHAT: ID 123456789 CHAT: LAST_NAME Bot @@ -46,5 +45,5 @@ SERVICE: 0 yes SERVICE: LEFTMEMBER 123456789 SERVICE: NEWMEMBER 123456789 SERVICE: NEWPHOTO -SERVICE: NEWTILE +SERVICE: NEWTITLE SERVICE: PINNED diff --git a/test/d-send_message-test/d-send_message-test.result b/test/d-send_message-test/d-send_message-test.result index da76762..c6c9c6a 100644 --- a/test/d-send_message-test/d-send_message-test.result +++ b/test/d-send_message-test/d-send_message-test.result @@ -2,24 +2,19 @@ chat:123456 JSON:"text":"\# test for text only output" URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage chat:123456 JSON:"text":"This is a normal text" -URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage -chat:123456 JSON:"text":"This is a normal text -with a line break" URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage chat:123456 JSON:"text":" This is a HTML<\/b> text","parse_mode":"html" URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage -chat:123456 JSON:"text":" This is a HTML<\/b> text -with a line break","parse_mode":"html" +chat:123456 JSON:"text":" This is a HTML<\/b> text\nwith a line break","parse_mode":"html" URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage chat:123456 JSON:"text":" This is a \*MARKDOWN\* text","parse_mode":"markdown" URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage -chat:123456 JSON:"text":" This is a \*MARKDOWN\* text -with a line break","parse_mode":"markdown" +chat:123456 JSON:"text":" This is a \*MARKDOWN\* text\nwith a line break","parse_mode":"markdown" URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage chat:123456 JSON:"text":"\# test for keyboard\, file\, venue output" @@ -40,11 +35,7 @@ URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?12345 chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]} URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage -chat:123456 JSON:"text":"STABILO 88\/240 Fineliner point 88 - -[https:\/\/images\-na\.ssl\-images\-amazon\.com\/images\/I\/41oypA3kmHL\.l_SX300\.jpg] -second part of text -plus newline\.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen \.\.\.", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]} +chat:123456 JSON:"text":"STABILO 88\/240 Fineliner point 88\n\n[https:\/\/images\-na\.ssl\-images\-amazon\.com\/images\/I\/41oypA3kmHL\.l_SX300\.jpg]\nsecond part of text\nplus newline\.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen \.\.\.", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]} URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?123456789:BASHBOTTESTSCRIPTbashbottestscript_/sendMessage chat:123456 JSON:"text":"\# test for sendfile" diff --git a/test/d-user_is-test.sh b/test/d-user_is-test.sh index 64e0095..aae5223 100755 --- a/test/d-user_is-test.sh +++ b/test/d-user_is-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.98-pre2-0-ga597303 +#### $$VERSION$$ v0.98-pre2-8-ga656533 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -21,13 +21,17 @@ source "${TESTDIR}/commands.sh" source # first user asking for botadmin will botadmin echo "Check \"user_is_botadmin\" ..." -echo '?' >"${ADMINFILE}" # auto mode +printf '["botadmin"] "?"\n' >>"${ADMINFILE}" # auto mode +echo "BOTADMIN ..." user_is_botadmin "BOTADMIN" || exit 1 # should never fail +echo "NOBOTADMIN ..." user_is_botadmin "NOBOTADMIN" && exit 1 # should fail +echo "BOTADMIN ..." user_is_botadmin "BOTADMIN" || exit 1 # same name as first one, should work -if [ "$(cat "${ADMINFILE}")" = "BOTADMIN" ]; then +echo "Check config file ..." +if [ "$(getConfigKey "botadmin")" = "BOTADMIN" ]; then echo " ... \"user_is_botadmin\" seems to work as expected." else exit 1