From 48e6f64d58b87ddb7a27563d5953130d105bfda8 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sun, 21 Apr 2019 14:52:55 +0200 Subject: [PATCH] finalize process_message test --- bashbot.sh | 8 ++-- test/ALL-tests.inc.sh | 22 ++++++++++- test/ALL-tests.sh | 2 +- test/a-commit-test.sh | 2 +- test/a-push-test.sh | 2 +- test/c-init-test.sh | 2 +- test/d-process_message-test.sh | 28 +++++--------- .../d-process_message-test.input | 17 +++++---- .../d-process_message-test.result | 37 +++++++++++++++++++ 9 files changed, 84 insertions(+), 36 deletions(-) create mode 100644 test/d-process_message-test/d-process_message-test.result diff --git a/bashbot.sh b/bashbot.sh index 4093791..7828813 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -10,7 +10,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 # # Exit Codes: # - 0 sucess (hopefully) @@ -579,7 +579,7 @@ process_message() { # Document URLS[DOCUMENT]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","document","file_id"' <"$TMP")")")" # Photo - URLS[PHOTO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","photo",.*,"file_id"' <"$TMP")")")" + URLS[PHOTO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","photo",0,"file_id"' <"$TMP")")")" # Sticker URLS[STICKER]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","sticker","file_id"' <"$TMP")")")" # Video @@ -597,8 +597,8 @@ process_message() { CAPTION="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","caption"' <"$TMP")")" # Location - LOCATION[LONGITUDE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","location","longitude"' <"$TMP")")" - LOCATION[LATITUDE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","location","latitude"' <"$TMP")")" + LOCATION[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","longitude"' <"$TMP")" + LOCATION[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","latitude"' <"$TMP")" NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')" #rm "$TMP" } diff --git a/test/ALL-tests.inc.sh b/test/ALL-tests.inc.sh index b91723c..0e1b414 100755 --- a/test/ALL-tests.inc.sh +++ b/test/ALL-tests.inc.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 # common variables export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME @@ -22,6 +22,26 @@ export SUCCESS NOSUCCESS SUCCESS=" OK" NOSUCCESS=" FAILED!" +# default input, reference and output files +INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input" +REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result" +OUTPUTFILE="${TESTDIR}/${REFDIR}.out" + +# print arrays in reproducible order +print_array() { + local idx t + local arrays=( "${@}" ) + for idx in "${arrays[@]}"; do + declare -n temp="$idx" + for t in "${!temp[@]}"; do + printf "%s:\t%s\t%s\n" "$idx" "$t" "${temp[$t]}" + done | sort + done | grep -v '^USER: 0' +} + + +###### +# lets go ... echo "Running ${TESTNAME#? } ..." echo "............................" [ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1 diff --git a/test/ALL-tests.sh b/test/ALL-tests.sh index 4ef0e30..a0bdc0a 100755 --- a/test/ALL-tests.sh +++ b/test/ALL-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # this has to run once atfer git clone # and every time we create new hooks -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 # magic to ensure that we're always inside the root of our application, # no matter from which directory we'll run script diff --git a/test/a-commit-test.sh b/test/a-commit-test.sh index 1afc51e..1755b4f 100644 --- a/test/a-commit-test.sh +++ b/test/a-commit-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 ../dev/hooks/pre-commit.sh diff --git a/test/a-push-test.sh b/test/a-push-test.sh index 3e5d1f1..300a8ca 100644 --- a/test/a-push-test.sh +++ b/test/a-push-test.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 ../dev/hooks/pre-push.sh diff --git a/test/c-init-test.sh b/test/c-init-test.sh index a6c2561..5519e3f 100755 --- a/test/c-init-test.sh +++ b/test/c-init-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index fc9a275..ecbc737 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ 0.70-dev-21-gd4cd756 +#### $$VERSION$$ 0.70-dev-22-g26c8523 # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh @@ -12,32 +12,22 @@ cd "${TESTDIR}" || exit 1 # shellcheck source=./bashbot.sh source "${TESTDIR}/bashbot.sh" source -export UPDATE -UPDATE="$(cat ${DIRME}/${REFDIR}/${REFDIR}.input)" - # overwrite get_file for test get_file() { echo "$1" } +# get telegram input from file +export UPDATE +UPDATE="$(cat "${INPUTFILE}")" + set -x -process_message "0" >>${LOGFILE} 2>&1 -set +x +process_message "0" >>"${LOGFILE}" 2>&1; set +x cd "${DIRME}" || exit 1 # output processed input - -print_array() { - local idx t - local arrays=( "${@}" ) - for idx in "${arrays[@]}"; do - declare -n temp="$idx" - for t in "${!temp[@]}"; do - printf "%s:\t%s\t%s\n" "$idx" "$t" "${temp[$t]}" - done | sort - done | grep -v '^USER: 0' -} - -print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" +echo "Diff process_message input and output ..." +print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" >"${OUTPUTFILE}" +diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 echo "${SUCCESS}" diff --git a/test/d-process_message-test/d-process_message-test.input b/test/d-process_message-test/d-process_message-test.input index 274bee0..e99b23b 100644 --- a/test/d-process_message-test/d-process_message-test.input +++ b/test/d-process_message-test/d-process_message-test.input @@ -29,9 +29,9 @@ ["result",0,"message","reply_to_message","entities",0,"length"] 14 ["result",0,"message","reply_to_message","entities",0,"type"] "bold" ["result",0,"message","reply_to_message","entities",0] {"offset":12,"length":14,"type":"bold"} -["result",0,"message","reply_to_message","entities",0,"offset"] 61 -["result",0,"message","reply_to_message","entities",0,"length"] 5 -["result",0,"message","reply_to_message","entities",0,"type"] "bot_command" +["result",0,"message","reply_to_message","entities",1,"offset"] 61 +["result",0,"message","reply_to_message","entities",1,"length"] 5 +["result",0,"message","reply_to_message","entities",1,"type"] "bot_command" ["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a" ["result",0,"message","forward_from","id"] 123456789 ["result",0,"message","forward_from","is_bot"] false @@ -45,10 +45,10 @@ ["result",0,"message","photo",0,"width"] 67 ["result",0,"message","photo",0,"height"] 90 ["result",0,"message","photo",0] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC","file_size":1468,"width":67,"height":90} -["result",0,"message","photo",0,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC" -["result",0,"message","photo",0,"file_size"] 25125 -["result",0,"message","photo",0,"width"] 240 -["result",0,"message","photo",0,"height"] 320 +["result",0,"message","photo",1,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC" +["result",0,"message","photo",1,"file_size"] 25125 +["result",0,"message","photo",1,"width"] 240 +["result",0,"message","photo",1,"height"] 320 ["result",0,"message","photo",1] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC","file_size":25125,"width":240,"height":320} ["result",0,"message","photo",2,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABCVM2ZSdqfMZbfgDAAEC" ["result",0,"message","photo",2,"file_size"] 127851 @@ -75,7 +75,8 @@ ["result",0,"message","venue","address"] "Am Rhein 1" ["result",0,"message","venue","foursquare_id"] "4c4321afce54e21eee980d1a" ["result",0,"message","contact","phone_number"] "222222" -["result",0,"message","contact","first_name"] "ADAC Pannenhilfe" +["result",0,"message","contact","first_name"] "ADAC" +["result",0,"message","contact","last_name"] "Pannenhilfe" ["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD" ["result",0,"message","voice","duration"] 2 ["result",0,"message","voice","mime_type"] "audio/ogg" diff --git a/test/d-process_message-test/d-process_message-test.result b/test/d-process_message-test/d-process_message-test.result new file mode 100644 index 0000000..783bdfc --- /dev/null +++ b/test/d-process_message-test/d-process_message-test.result @@ -0,0 +1,37 @@ +USER: FIRST_NAME Kay +USER: ID 123456789 +USER: LAST_NAME M +USER: USERNAME Gnadelwartz +CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS +CHAT: FIRST_NAME Test +CHAT: ID 123456789 +CHAT: LAST_NAME Bot +CHAT: TITLE +CHAT: TYPE private +CHAT: USERNAME BotTest +REPLYTO: 0 Ich bin der Deal-O-Mat Bot. FΓΌr eine Liste der Befehle sende /help +REPLYTO: FIRST_NAME dealzbot +REPLYTO: ID 6542 +REPLYTO: LAST_NAME +REPLYTO: UID 987654321 +REPLYTO: USERNAME Deal_O_Mat_bot +FORWARD: FIRST_NAME Kay +FORWARD: ID 6541 +FORWARD: LAST_NAME M +FORWARD: UID 123456789 +FORWARD: USERNAME Gnadelwartz +URLS: AUDIO +URLS: DOCUMENT +URLS: PHOTO AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC +URLS: STICKER +URLS: VIDEO +URLS: VOICE AwADAgADOAQAAqd24Emnm_VGmmVEuAI +CONTACT: FIRST_NAME ADAC +CONTACT: LAST_NAME Pannenhilfe +CONTACT: NUMBER 222222 +CONTACT: USER_ID +CAPTION: 0 +LOCATION: LATITUDE 49.631824 +LOCATION: LONGITUDE 8.377072 +MESSAGE: 0 πŸ˜‚πŸ˜πŸ‘Œβ˜Ίβ€πŸ˜•πŸ˜ˆ#βƒ£πŸŒπŸŽ‰πŸ™ŠπŸ™‰β˜•πŸš€βœˆπŸš‚πŸ’―βœ”γ€½πŸ”š +MESSAGE: ID 6541