A test/.gitignore => test/.gitignore +4 -0
@@ 0,0 1,4 @@
+*.pem
+env/
+__pycache__
+.known_hosts
A test/root/empty.gmi => test/root/empty.gmi +0 -0
A test/run-tests.sh => test/run-tests.sh +27 -0
@@ 0,0 1,27 @@
+#!/bin/sh
+
+if [ -d "./env" ]; then
+
+ # build moongem if it's not built already
+ mkdir -p ../build
+ pushd ../build
+ cmake -DCMAKE_BUILD_TYPE=Release ..
+ make -j moongem
+ popd
+
+ # run the server and fork
+ ../build/moongem -p 1966 -c cert.pem -k key.pem -r root/ >/dev/null &
+ mgpid=$!
+
+ echo "Server PID: $mgpid"
+
+ # run test script
+ source env/bin/activate
+ python test.py
+ deactivate
+
+ # kill the server
+ kill -s TERM $mgpid
+else
+ echo "Run setup.sh first in order to configure the testing environment."
+fi
A test/setup.sh => test/setup.sh +14 -0
@@ 0,0 1,14 @@
+#!/bin/sh
+
+
+# 1. Set up Python virtualenv and install requirements
+
+python -m venv env
+source env/bin/activate
+pip install ignition-gemini
+deactivate
+
+
+# 2. Generate certificates
+
+openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650 -nodes -subj "/CN=localhost"
A test/test.py => test/test.py +21 -0
@@ 0,0 1,21 @@
+import test_definitions as td
+import ignition as ig
+import sys
+
+tests = {
+ 'empty.gmi': td.exists,
+ 'does_not_exist.gmi': td.does_not_exist
+}
+
+def main():
+ for route, func in tests.items():
+ response = ig.request(f'//localhost:1966/{route}')
+ passed, msg = func(response)
+ if not passed:
+ print(f'[{func.__name__}] failed ({route}): {msg}')
+ sys.exit(-1)
+ else:
+ print(f'{func.__name__} passed ({route})')
+
+if __name__ == '__main__':
+ main()
A test/test_definitions.py => test/test_definitions.py +19 -0
@@ 0,0 1,19 @@
+import ignition as ig
+from ignition.response import BaseResponse
+
+def fail(msg):
+ return False, msg
+
+def ok():
+ return True, None
+
+def exists(response: BaseResponse):
+ if response.status == ig.RESPONSE_STATUSDETAIL_PERM_FAILURE_NOT_FOUND:
+ return fail('Resource was not found')
+ return ok()
+
+def does_not_exist(response: BaseResponse):
+ if response.status != ig.RESPONSE_STATUSDETAIL_PERM_FAILURE_NOT_FOUND:
+ return fail('Resource was found')
+ return ok()
+