From f686102cc3129b62339e3166afdf492015deee07 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 12:31:26 +0200 Subject: Adding debian version 2.19+dfsg-1. Signed-off-by: Daniel Baumann --- debian/tests/test-simple | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 debian/tests/test-simple (limited to 'debian/tests/test-simple') diff --git a/debian/tests/test-simple b/debian/tests/test-simple new file mode 100644 index 0000000..5502e55 --- /dev/null +++ b/debian/tests/test-simple @@ -0,0 +1,97 @@ +#!/bin/sh + +# Simple test that we can connect to a test server, and send a message with irk +# We use irclib to provide the test server and watch a test client to ensure that +# the correct message is broadcast to the correct channels + +set -e + +WORKDIR=$(mktemp -d) +trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM +cd $WORKDIR + +# setup test client +cat << EOF > testclient.py +# Simple test case for irker +# Based on irccat.py in the irclib package by Joel Rosdahl + +import sys + +import irc.client + +logfile = None + +def on_connect(connection, event): + connection.join("#testchan") + +def on_pubmsg(connection, event): + logfile.write(event.arguments[0]) + logfile.write("\n") + logfile.write(event.source) + logfile.write("\n") + logfile.flush() + +def on_disconnect(connection, event): + raise SystemExit() + +def main(): + global logfile + client = irc.client.IRC() + try: + c = client.server().connect("localhost", 6667, "testclient") + except irc.client.ServerConnectionError: + print(sys.exc_info()[1]) + raise SystemExit(1) + + logfile = open(sys.argv[1], 'w') + + c.add_global_handler("welcome", on_connect) + c.add_global_handler("pubmsg", on_pubmsg) + + client.process_forever() + +if __name__ == '__main__': + main() +EOF + +# This is needed to make irkerd start on some lxc containers, otherwise +# the irker user can't execute anything, but it will fail in other +# cases, so we make it non-fatal +chmod 755 / || echo "chmod failed - assuming everything is fine" + +# Ensure irkerd is running +systemctl restart irkerd + +python3 -m irc.server 2>server.log & +sleep 3 +python3 ./testclient.py client.log & +# Give time for everything to start up and connect +sleep 3 + +# Send a message that the client should see +irk 'irc://localhost:6667/testchan' 'Test message 1' +sleep 1 +# This should not show up in the client log +irk 'irc://localhost:6667/differentchan' 'Test message 2' +sleep 1 +# this should also be seen +irk 'irc://localhost:6667/testchan' 'Test message 3' +sleep 1 + +# kill background tasks +pkill -f testclient.py +pkill -f irc.server + +# Inspect client log +# check that we saw irker connect +grep -q 'irker[0-9]' client.log + +grep -q 'Test message 1' client.log +grep -q 'Test message 3' client.log + +if grep -q 'Test message 2' client.log; then + echo "Found unexpected 'Test message 2' in client.log" + exit 1 +fi + +echo "Simple irker daemon test succeeded" -- cgit v1.2.3