add tests for ENV, fix some small nitpits

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-01 11:46:57 +02:00
parent 8883cc9028
commit 7c112122e8
54 changed files with 193 additions and 98 deletions

1
.gitignore vendored
View File

@ -5,5 +5,6 @@
*.save
*.log
/JSON.sh/
/data-bot-bash/
/tmp-bot-bash/
/dist/

View File

@ -97,6 +97,6 @@
<p><span class="citation">@Gnadelwartz</span></p>
<h2 id="thats-it">Thats it!</h2>
<p>If you feel that theres something missing or if you found a bug, feel free to submit a pull request!</p>
<h4 id="version-v0.7-rc1-0-g8279bdb"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.7-rc1-0-g8279bdb</h4>
<h4 id="version-v0.70-rc1-0-g8883cc9"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.70-rc1-0-g8883cc9</h4>
</body>
</html>

View File

@ -93,4 +93,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -130,4 +130,4 @@ health status
If you feel that there's something missing or if you found a bug, feel free to
submit a pull request!
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -1,7 +1,7 @@
#!/bin/sh
# description: Start or stop telegram-bash-bot
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# shellcheck disable=SC2009
# shellcheck disable=SC2181

View File

@ -12,7 +12,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
#
# Exit Codes:
# - 0 sucess (hopefully)
@ -70,7 +70,7 @@ JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}/JSON.sh/JSON.sh}"
if [ ! -f "${JSONSHFILE}" ]; then
echo "Seems to be first run, Downloading ${JSONSHFILE}..."
mkdir "JSON.sh" 2>/dev/null;
[[ "${JSONSHFILE}" = "${RUNDIR}/JSON.sh/JSON.sh" ]] && mkdir "JSON.sh" 2>/dev/null;
curl -sL -o "${JSONSHFILE}" "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh"
chmod +x "${JSONSHFILE}"
fi
@ -587,7 +587,7 @@ bot_init() {
exit 3
else
echo "Adjusting user \"${TOUSER}\" files and permissions ..."
sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' bashbot.rc
[ -w "bashbot.rc" ] && sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' "bashbot.rc"
chown -R "$TOUSER" . ./*
chmod 711 .
chmod -R a-w ./*

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -3,7 +3,7 @@
#
# works together with git pre-push.sh and ADD all changed files since last push
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
############
# NOTE: you MUST run install-hooks.sh again when updating this file!
@ -42,12 +42,12 @@ else
exit 1
fi
REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed 's/.*\/v//')"
REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed -e 's/.*\/v//' -e 's/-.*//')"
VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//')"
# LOCAL version must greater than latest REMOTE release version
if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then
if (( $(echo "${VERSION} >= ${REMOTEVER}" | bc -l) )); then
# update version in bashbot files on push
set +f
[ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")"
@ -57,8 +57,8 @@ if (( $(echo "${VERSION} > ${REMOTEVER}" | bc -l) )); then
dev/version.sh ${LASTFILES} 2>/dev/null || exit 1
echo " OK"
else
echo "Error: local version ${VERSION} must be greater than latest release version."
echo "use \"git tag ...\" to create a local version greater than ${REMOTEVER}"
echo "Error: local version ${VERSION} must be greater or equal to release version ${REMOTEVER}."
echo "use \"git tag ...\" to create a new local version"
exit 1
fi

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
############
# NOTE: you MUST run install-hooks.sh again when updating this file!

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,3 +1,3 @@
# list of additional files to check from shellcheck
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
bashbot.rc

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# shellcheck disable=SC2016
#
# Easy Versioning in git:

View File

@ -63,5 +63,5 @@ The old format is supported for backward compatibility, but may fail for corner
#### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -65,5 +65,5 @@ group. This step is up to you actually.
#### [Prev Installation](0_install.md)
#### [Next Getting started](2_usage.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -167,5 +167,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -177,5 +177,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
#### [Prev Getting started](2_usage.md)
#### [Next Expert Use](4_expert.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
#### [Prev Expert Use](4_expert.md)
#### [Next Best Practice](5_practice.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -153,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam
#### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -489,5 +489,5 @@ Send Input from Telegram to waiting Interactive Chat.
#### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -92,5 +92,5 @@ fi
#### [Prev Function Reference](6_reference.md)
#### [Next Bashbot Environment](8_custom.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -117,5 +117,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
#### [Prev Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -9,13 +9,12 @@ An example crontab is provided in ```examples/bashbot.cron```, see [Expert use](
### Interactive chats
Two examples for interactive scripts are provided as **calc.sh** and **question.sh**, see [Advanced use](../doc/3_advanced.md#Interactive-Chats)
### Background jobs
### Background scripts
Background jobs are an easy way to provide sceduled messages or alerts if something happens.
**notify.sh** is a simple example on how to send a message every x seonds, e.g. current time.
**background-scripts** contains a more concrete example on how to start and stop different scripts plus some example backgound scripts.
**background-scripts** contains a more useful example on how to start and stop different scripts plus some example backgound scripts.
```
mycommands.sh - /run_xxx and /kill-xxx wil start any script named run_xxx.sh
@ -28,16 +27,31 @@ Background jobs are an easy way to provide sceduled messages or alerts if someth
**Note:** Output of system commands often contains newlines, each newline results in a telegram message, the function 'send_telegram' in
mycommands.sh avoids this by converting each newline to ' mynewlinestartshere ' before output the string.
**system-status** contains an example with commands showing system status. This example is adapted from https://github.com/RG72/telegram-bot-bash
### Ssystem Status
**send-system-status** contains an example for commands showing status of different subsystems. This example is adapted from
https://github.com/RG72/telegram-bot-bash to current bashbot commands, but not fully tested. This will show how easy you can
convert existing bots.
```
mycommands.sh - sommands to show system status
mycommands.sh - commands to show system status
botacl - controls who can show system status
*Availiable commands*:
/se *sensors*
/smb *smbstatus*
/free *memory status*
/md *raid status*
/lvm *lvm status*
/lvsd *Datailed lvm status*
/df *disk space*
/ifconfig *ifconfig output*
/smart *sda* _smart status for sda drive_
```
### Use bashbot from external scripts
### External scripts
**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users.
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9

View File

@ -4,7 +4,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,7 +2,7 @@
# file: run_filename
# background job to display content of all new files in WATCHDIR
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -2,7 +2,7 @@
# file: run_filename
# background job to display all new files in WATCHDIR
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -4,7 +4,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -7,7 +7,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
SHELL=/bin/sh

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -4,7 +4,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment

View File

@ -1,6 +1,7 @@
# file: botacl
# a user not listed here, will return false from 'user_is_allowed'
#
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# Format:
# user:ressource:chat

View File

@ -5,7 +5,7 @@
# to show how you can customize bashbot by only editing mycommands.sh
# NOTE: this is not tested, simply copied from original source and reworked!
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034
@ -20,65 +20,56 @@ bashbot_info='This bot allows you to request status of your system.
To begin using the bot, try with the /help command.
'
bashbot_help='*Availiable commands*:
/s *sensors*
/ss *smbstatus*
/se *sensors*
/smb *smbstatus*
/free *memory status*
/md *raid status*
/lvs *lvm status*
/lvm *lvm status*
/lvsd *Datailed lvm status*
/df *disk space*
/ifconfig *ifconfig output*
/smart *-d sda* _smart status for sda drive_
'
IDMESSAGEPRE="Your chat identifier is"
# your additional bahsbot commands
# NOTE: command can have @botname attached, you must add * in case tests...
mycommands() {
if user_is_allowed "${USER[ID]}" "systemstatus"; then
case "$MESSAGE" in
'/md'|'raid_status') msg="$(cat /proc/mdstat)";;
'/ss'|'smbstatus')
msg=""
smbstatus >/tmp/smbstatus
send_doc "$TARGET" "/tmp/smbstatus"
prevActiveTime=$curTime
;;
'/s'|'sensors'|'/sensors') msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";;
'/free') msg="$(free -h)";;
'/pvs') msg="$(pvs)";;
'/ifconfig') msg="$(ifconfig)";;
'/vgs') msg="$(vgs)";;
'/lvs') msg="$(lvs | sed -r 's/\s+/\n/g')";;
'/lvsd') msg="$(lvs -a -o +devices | sed -r 's/\s+/\n/g')";;
'/smart'|'/smartctl')
if [ "$OPTARG" == "" ]; then
msg="example \`/smart sda\`"
else
drive="$(echo "$OPTARG" | cut -c 1-3)"
echo "smartctl -a /dev/$drive"
msg="$(smartctl -a "/dev/$drive")"
fi
[[ "$MESSAGE" = '/'* ]] || return
set +f
# shellcheck disable=SC2206
local arg=( $MESSAGE )
set -f
local cmd="${arg[0]}"
local msg=""
if user_is_botadmin || user_is_allowed "${USER[ID]}" "systemstatus"; then
case "$cmd" in
'/md'*) msg="$(cat /proc/mdstat)";;
'/smb'*) msg="$(smbstatus)" ;;
'/se'*) msg="$(sensors | sed -r 's/\s|\)+//g' | sed -r 's/\(high=|\(min=/\//' | sed -r 's/\,crit=|\,max=/\//')";;
'/free'*) msg="$(free -h)";;
'/pvs'*) msg="$(pvs)";;
'/ifc'*) msg="$(ifconfig)";;
'/vgs'*) msg="$(vgs)";;
'/lvm'*) msg="$(lvs | sed -r 's/\s+/\n/g')";;
'/lvsd'*) msg="$(lvs -a -o +devices | sed -r 's/\s+/\n/g')";;
'/smart'*)
[ "${arg[0]}" == "" ] && msg="example \`/smart sda\`" && return
drive="$(echo "${arg[0]}" | cut -c 1-3)"
echo "smartctl -a /dev/$drive"
msg="$(smartctl -a "/dev/$drive")"
;;
'/df') msg="$(df -h | sed -r 's/^/\n/' | sed -r 's/\s+/\n/g')";;
esac
if [ "$msg" != "" ]; then
send_telegram "${CHAT[ID]}" "$msg"
send_normal_message "${CHAT[ID]}" "$msg"
fi
else
send_normal_message "Sorry, you are not allowed to use this bot!"
send_normal_message "${USER[ID]}" "Sorry, you are not allowed to use this bot!"
fi
}
# place your processing functions here
# converts newlines for telegram and send as one message
# $1 chat
# $2 message
send_telegram() {
# output to telegram
send_message "${1}" "$(sed <<< "${2}" -e ':a;N;$!ba;s/\n/ mynewlinestartshere /g')"
} # 2>>"$0.log"

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
#
# source from commands.sh to use the aliases

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# source from commands.sh if you want ro use interactive or background jobs

View File

@ -5,6 +5,6 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# source from commands.sh to use the inline functions

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ...
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034

View File

@ -2,7 +2,7 @@
#
# ADD a new test skeleton to test dir, but does not activate test
#
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
@ -11,11 +11,12 @@ export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
TESTNAME="${REFDIR//-/ }"
# common filenames
export TOKENFILE ACLFILE COUNTFILE ADMINFILE
export TOKENFILE ACLFILE COUNTFILE ADMINFILE DATADIR
TOKENFILE="token"
ACLFILE="botacl"
COUNTFILE="count"
ADMINFILE="botadmin"
DATADIR="data-bot-bash"
# SUCCESS NOSUCCES
export SUCCESS NOSUCCESS

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
../dev/hooks/pre-commit.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh
@ -20,14 +20,14 @@ do
[ "${i}" = "1" ] && echo " ... JSON.sh -s -b -n"
[ "${i}" = "2" ] && echo " ... JSON.sh"
set +f
for jsonfile in ${REFDIR}/*.log
for jsonfile in ${REFDIR}/*.in
do
set -f
[ "${i}" = "1" ] && "${JSON}" -s -b -n <"${jsonfile}" >"${jsonfile}.out-${i}"
[ "${i}" = "2" ] && "${JSON}" <"${jsonfile}" >"${jsonfile}.out-${i}"
# output processed input
diff -c "${jsonfile}.result-${i}" "${jsonfile}.out-${i}" || exit 1
diff -c "${jsonfile%.in}.result-${i}" "${jsonfile}.out-${i}" || exit 1
done
echo "${SUCCESS}"
done

View File

@ -0,0 +1,2 @@
{"ok":true,"result":[{"update_id":146860898,
"message":{"message_id":6620,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934213,"location":{"latitude":49.630443,"longitude":8.361698},"venue":{"location":{"latitude":49.630443,"longitude":8.361698},"title":"Vannini","address":"K\u00e4mmererstr. 3","foursquare_id":"4bf94ec05ec320a115f889d3"}}}]}

View File

@ -0,0 +1,2 @@
{"ok":true,"result":[{"update_id":146860896,
"message":{"message_id":6618,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":123456789,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934195,"voice":{"duration":1,"mime_type":"audio/ogg","file_id":"AwADAgADKQMAAh638UnbhHGzIMozZgI","file_size":3963}}}]}

View File

@ -0,0 +1,2 @@
{"ok":true,"result":[{"update_id":146860897,
"message":{"message_id":6619,"from":{"id":123456789,"is_bot":false,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","language_code":"de"},"chat":{"id":586928566,"first_name":"Kay","last_name":"M","username":"Gnadelwartz","type":"private"},"date":1555934204,"contact":{"phone_number":"222222","first_name":"ADAC Pannenhilfe","vcard":"BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"}}}]}

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.7-rc1-0-g8279bdb
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh

78
test/e-env-test.sh Executable file
View File

@ -0,0 +1,78 @@
#!/usr/bin/env bash
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
# 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
# cp bashbot files to new localtions
set +f
# shellcheck disable=SC2086
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
set -f
cp "${TESTDIR}/bashbot.sh" "${BASHBOT_BIN}" || exit 1
TESTTOKEN="bashbottestscript"
TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}"
echo "Check first run in ENVIRONMENT ..."
# run bashbot first time with init
"${BASHBOT_BIN}/bashbot.sh" init >"${LOGFILE}" <<EOF
$TESTTOKEN
nobody
botadmin
EOF
echo "${SUCCESS}"
echo "Check if files are placed in ENVIRONMENT ..."
if [ ! -f "${BASHBOT_JSONSH}" ]; then
echo "${NOSUCCESS} ${BASHBOT_JSONSH} missing!"
exit 1
fi
if [ ! -d "${BASHBOT_VAR}/${DATADIR}" ]; then
echo "${NOSUCCESS} ${DATADIR} missing!"
exit 1
fi
if [ ! -f "${BASHBOT_VAR}/${COUNTFILE}" ]; then
echo "${NOSUCCESS} ${BASHBOT_VAR}/${COUNTFILE} missing!"
exit 1
fi
echo " ... BASHBOT_VAR seems to work!"
echo "${SUCCESS}"
# compare files with refrence files
export FAIL="0"
for file in ${TESTFILES}
do
ls -d "${BASHBOT_ETC}/${file}" >>"${LOGFILE}"
if ! diff -q "${BASHBOT_ETC}/${file}" "${REFDIR}/${file}" >>"${LOGFILE}"; then echo "${NOSUCCESS} Fail diff ${file}!"; FAIL="1"; fi
done
echo " ... BASHBOT_ETC seems to work!"
echo "${SUCCESS}"

1
test/e-env-test/botacl Normal file
View File

@ -0,0 +1 @@

1
test/e-env-test/botadmin Normal file
View File

@ -0,0 +1 @@
?

1
test/e-env-test/token Normal file
View File

@ -0,0 +1 @@
bashbottestscript