xmppmirror/test/test.sh

60 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2022-06-13 17:33:08 +00:00
#!/bin/bash
2022-06-13 23:21:53 +00:00
# Check if docker is installed
if ! command -v docker run &> /dev/null
then
echo "No docker detected. If you are running debian based system, you can install docker with"
2022-06-13 23:28:08 +00:00
echo "sudo apt install docker.io"
2022-06-13 23:21:53 +00:00
exit
fi
echo "Docker detected"
2022-06-13 17:33:08 +00:00
# Run ejabberd docker as a daemon
2022-06-13 23:21:53 +00:00
echo "Starting ejabberd docker container"
2022-06-13 17:33:08 +00:00
docker run --name xmppbot-test -d -p 25222:5222 ejabberd/ecs
# Wait few seconds for ejabberd to boot
sleep 5
# Create acounts for admin and xmppbot
docker exec -it xmppbot-test bin/ejabberdctl register admin localhost admintestpassword
docker exec -it xmppbot-test bin/ejabberdctl register xmppbot localhost bottestpassword
# Create MUC rooms for testing
docker exec -it xmppbot-test bin/ejabberdctl create_room testroom1 conference.localhost localhost
docker exec -it xmppbot-test bin/ejabberdctl create_room testroom2 conference.localhost localhost
# Run xmpp mirror bot
2022-06-13 23:21:53 +00:00
echo "Running xmpp mirror bot"
2022-06-13 20:24:07 +00:00
python3 ../xmppmirror & XMPPMIRRORPID=$!
2022-06-13 17:33:08 +00:00
# Run xmpp test bot
2022-06-13 23:21:53 +00:00
echo "Running test bot"
2022-06-13 20:24:07 +00:00
python3 testbot & TESTBOTPID=$!
# Wait for bots to connect
sleep 10
# Wait certain amount of time for every test message in the file
2022-06-13 20:29:53 +00:00
for i in $(cat testmsgs.txt); do sleep 5; done
2022-06-13 20:24:07 +00:00
# Kill bots
2022-06-13 23:21:53 +00:00
if ps -p $XMPPMIRRORPID > /dev/null
then
echo "Killing xmpp mirror bot"
kill $XMPPMIRRORPID
fi
if ps -p $TESTBOTPID > /dev/null
then
echo "Killing test bot"
kill $TESTBOTPID
fi
2022-06-13 17:33:08 +00:00
# Stop and remove containter
2022-06-13 23:21:53 +00:00
echo "Stopping and removing docker container"
2022-06-13 17:33:08 +00:00
docker stop xmppbot-test
docker rm xmppbot-test