test: add integration tests
authorKyle Fuller <redacted>
Thu, 4 Apr 2019 22:36:13 +0000 (00:36 +0200)
committerDennis Collaris <redacted>
Mon, 17 Jun 2019 21:06:56 +0000 (23:06 +0200)
.circleci/config.yml
Makefile
test/fixtures/configs/znc.conf [new file with mode: 0644]
test/test_palaver.py [new file with mode: 0644]

index 3a415973a00648d7908e59308e2f4578c2d9ee6b..2ca09892f4c7e333973699e5205e3f68e0ce8666 100644 (file)
@@ -5,6 +5,7 @@ workflows:
     jobs:
       - build-znc1.6
       - build-znc1.7
+      - test
 
 jobs:
   build: &build
@@ -25,3 +26,14 @@ jobs:
     <<: *build
     docker:
       - image: znc:1.7
+
+  test:
+    <<: *build
+
+    steps:
+      - checkout
+      - run: |
+          export PATH="/opt/znc/bin:$PATH"
+          pip3 install pytest-asyncio
+          znc-buildmod palaver.cpp
+          make test-integration
index e37d4a65700d2b64a66198ef1904b8158d9dd4d1..bce5e071c0b14a5909dbe67efb836b977ed4692a 100644 (file)
--- 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 (file)
index 0000000..450898d
--- /dev/null
@@ -0,0 +1,31 @@
+// 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
+<Listener l>
+       Port = 6698
+       IPv4 = true
+       IPv6 = true
+       SSL = false
+</Listener>
+LoadModule = webadmin
+
+<User admin>
+       Pass       = sha256#dc7b7a09f10a4d5e09f0d4f318199a4c392aeefbbba4ad6eb1367cb7b3d62da3#.SlDWD:dZaFrkEp8.R8A#
+       Admin      = true
+       Nick       = admin
+       AltNick    = admin_
+       Ident      = admin
+       LoadModule = controlpanel
+
+       <Network admin>
+       </Network>
+</User>
diff --git a/test/test_palaver.py b/test/test_palaver.py
new file mode 100644 (file)
index 0000000..53c656d
--- /dev/null
@@ -0,0 +1,51 @@
+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):
+    running_as_root = os.getuid() == 0
+    allow_root = ' --allow-root' if running_as_root else ''
+    
+    proc = await asyncio.create_subprocess_shell(f'znc -d test/fixtures --foreground --debug{allow_root}', loop=event_loop)
+    time.sleep(31 if running_as_root else 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'
+
+    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)
git clone https://git.99rst.org/PROJECT