summaryrefslogtreecommitdiffstats
path: root/debian/tests/test-simple
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests/test-simple')
-rw-r--r--debian/tests/test-simple118
1 files changed, 118 insertions, 0 deletions
diff --git a/debian/tests/test-simple b/debian/tests/test-simple
new file mode 100644
index 0000000..1eeb8dd
--- /dev/null
+++ b/debian/tests/test-simple
@@ -0,0 +1,118 @@
+#!/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 <joel@rosdahl.net>
+
+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
+
+# 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
+
+# Manually run irkerhook.py, to ensure that works
+# We create a git repo for this, since irkerhook needs a repo to function
+mkdir test_repo
+cd test_repo
+# Redirect git warnings so they're not fatal
+git init 2> git.log
+git config user.email 'test@localhost'
+git config user.name 'Test Author'
+git config irker.channels 'irc://localhost:6667/testchan'
+touch start
+git add start
+git commit -m "Test commit" ./start
+# Check that irkerhook outputs sane info
+irkerhook -n | grep -q '"privmsg": "test_repo: Test Author test_repo:.* : Test commit "'
+# Check that irkerhook sends to the right place
+irkerhook
+# We need a moment for the irc server to process everything
+sleep 1
+cd ..
+grep -q 'test_repo: Test Author test_repo:.* : Test commit' client.log
+
+# kill background tasks
+pkill -f testclient.py
+pkill -f irc.server
+
+echo "Simple irker daemon tests succeeded"