From: Kyle Fuller Date: Thu, 4 Apr 2019 22:36:13 +0000 (+0200) Subject: test: add integration tests X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=refs%2Fheads%2Fkylef%2Fint-test;p=znc-palaver.git test: add integration tests --- diff --git a/.circleci/config.yml b/.circleci/config.yml index 3a41597..aa7b65b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,7 @@ workflows: jobs: - build-znc1.6 - build-znc1.7 + - test jobs: build: &build @@ -25,3 +26,13 @@ jobs: <<: *build docker: - image: znc:1.7 + + test: + <<: *build + + steps: + - checkout + - run: + pip install pytest-asyncio + /opt/znc/bin/znc-buildmod palaver.cpp + make test-integration diff --git a/Makefile b/Makefile index e37d4a6..bce5e07 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ -palaver.so: test palaver.cpp +build: test palaver.so + +palaver.so: palaver.cpp @echo "Building palaver.so" @znc-buildmod palaver.cpp install: palaver.so @echo "Installing palaver.so to $(HOME)/.znc/modules/palaver.so" @mkdir -p $(HOME)/.znc/modules - @cp palaver.so $(HOME)/.znc/modules/palaver.so + @cp $^ $(HOME)/.znc/modules/palaver.so clean: -rm -f palaver.so test-regex @@ -15,8 +17,16 @@ uninstall: -rm -f $(HOME)/.znc/modules/palaver.so test-regex: test-regex.cpp - @$(CXX) -std=c++11 test-regex.cpp -o test-regex + @$(CXX) -std=c++11 $< -o $@ .PHONY: test test: test-regex @./test-regex + +test/fixtures/modules/palaver.so: palaver.so + @mkdir -p test/fixtures/modules + @cp $< $@ + +.PHONY: test-integration +test-integration: test/fixtures/modules/palaver.so + pytest diff --git a/test/fixtures/configs/znc.conf b/test/fixtures/configs/znc.conf new file mode 100644 index 0000000..fa4dac2 --- /dev/null +++ b/test/fixtures/configs/znc.conf @@ -0,0 +1,28 @@ +// WARNING +// +// Do NOT edit this file while ZNC is running! +// Use webadmin or *controlpanel instead. +// +// Altering this file by hand will forfeit all support. +// +// But if you feel risky, you might want to read help on /znc saveconfig and /znc rehash. +// Also check https://wiki.znc.in/Configuration + +LoadModule = palaver +Version = 1.7.1 + + Port = 6698 + IPv4 = true + IPv6 = true + SSL = false + +LoadModule = webadmin + + + Pass = sha256#dc7b7a09f10a4d5e09f0d4f318199a4c392aeefbbba4ad6eb1367cb7b3d62da3#.SlDWD:dZaFrkEp8.R8A# + Admin = true + Nick = admin + AltNick = admin_ + Ident = admin + LoadModule = controlpanel + diff --git a/test/test_palaver.py b/test/test_palaver.py new file mode 100644 index 0000000..ed097c9 --- /dev/null +++ b/test/test_palaver.py @@ -0,0 +1,50 @@ +import time +import os +import asyncio +import pytest + +# All test coroutines will be treated as marked. +pytestmark = pytest.mark.asyncio + +async def setUp(event_loop): + proc = await asyncio.create_subprocess_shell('znc -d test/fixtures --foreground --debug', loop=event_loop) + time.sleep(1) + + (reader, writer) = await asyncio.open_connection('localhost', 6698, loop=event_loop) + writer.write(b'PASS admin\r\n') + writer.write(b'USER admin admin admin\r\n') + writer.write(b'NICK admin\r\n') + await writer.drain() + + line = await reader.readline() + assert line == b':irc.znc.in 001 admin :Welcome to ZNC\r\n' + + line = await reader.readline() + assert line == b":*status!znc@znc.in PRIVMSG admin :You are currently disconnected from IRC. Use 'connect' to reconnect.\r\n" + return (proc, reader, writer) + +async def tearDown(proc): + proc.kill() + await proc.wait() + + os.remove('test/fixtures/moddata/palaver/palaver.conf') + +async def test_registering_device(event_loop): + (proc, reader, writer) = await setUp(event_loop) + + writer.write(b'PALAVER IDENTIFY 9167e47b01598af7423e2ecd3d0a3ec4 611d3a30a3d666fc491cdea0d2e1dd6e b758eaab1a4611a310642a6e8419fbff\r\n') + await writer.drain() + + line = await reader.readline() + assert line == b'PALAVER REQ *\r\n' + + writer.write(b'PALAVER BEGIN 9167e47b01598af7423e2ecd3d0a3ec4 611d3a30a3d666fc491cdea0d2e1dd6e\r\n') + writer.write(b'PALAVER SET PUSH-TOKEN 605b64f5addc408fcfa7ff0685e2d065fdecb127\r\n') + writer.write(b'PALAVER SET PUSH-ENDPOINT https://api.palaverapp.com/1/push\r\n') + writer.write(b'PALAVER ADD MENTION-KEYWORD cocode\r\n') + writer.write(b'PALAVER ADD MENTION-KEYWORD {nick}\r\n') + writer.write(b'PALAVER END\r\n') + await writer.drain() + time.sleep(1) + + await tearDown(proc)