aboutsummaryrefslogtreecommitdiffstats
path: root/test/functional/lib
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2016-07-02 17:48:58 +0200
committerAndrew Lewis <nerf@judo.za.org>2016-07-02 18:36:15 +0200
commitad797afed513439cb2cd81de185b75880ea9f8aa (patch)
treed3826459a27b101b0051abde7681ad752760f03c /test/functional/lib
parente3a301a85d355a7f559173b88613fb4da5fbd016 (diff)
downloadrspamd-ad797afed513439cb2cd81de185b75880ea9f8aa.tar.gz
rspamd-ad797afed513439cb2cd81de185b75880ea9f8aa.zip
[Test] Add & rework functional tests
- Machine formatted test data - More idiomatic use of test framework - Added tests for fuzzy & redis statistics
Diffstat (limited to 'test/functional/lib')
-rw-r--r--test/functional/lib/rspamd.py8
-rw-r--r--test/functional/lib/rspamd.robot80
-rw-r--r--test/functional/lib/vars.py2
3 files changed, 54 insertions, 36 deletions
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py
index 93ec4c430..10caab3ca 100644
--- a/test/functional/lib/rspamd.py
+++ b/test/functional/lib/rspamd.py
@@ -29,12 +29,6 @@ def get_test_directory():
def make_temporary_directory():
return tempfile.mkdtemp()
-def populate_rspamd_config(template_file, temporary_dir, **config):
- t = string.Template(open(template_file).read())
- f = open("%s/rspamd.conf" % temporary_dir, "w")
- f.write(t.safe_substitute(config))
- f.close()
-
def process_should_exist(pid):
pid = int(pid)
os.kill(pid, 0)
@@ -75,7 +69,7 @@ def update_dictionary(a, b):
a.update(b)
return a
-def shutdown_rspamd(pid):
+def shutdown_process(pid):
pid = int(pid)
process_should_exist(pid)
i = 0
diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot
index b6180d40d..ded537e03 100644
--- a/test/functional/lib/rspamd.robot
+++ b/test/functional/lib/rspamd.robot
@@ -1,7 +1,7 @@
*** Settings ***
-Library Collections
-Library OperatingSystem
-Library Process
+Library Collections
+Library OperatingSystem
+Library Process
*** Keywords ***
Check Rspamc
@@ -32,42 +32,64 @@ Follow Rspamd Log
... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
Generic Setup
- ${TMPDIR} ${RSPAMD_PID} ${RSPAMD_LOGPOS} = Run Rspamd
+ [Arguments] @{vargs}
+ ${TMPDIR} ${RSPAMD_PID} ${RSPAMD_LOGPOS} = Run Rspamd @{vargs}
Run Keyword If '${RSPAMD_SCOPE}' == 'Test' Export Rspamd Vars To Test ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID}
... ELSE IF '${RSPAMD_SCOPE}' == 'Suite' Export Rspamd Vars To Suite ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID}
... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
Generic Teardown
- Shutdown Rspamd ${RSPAMD_PID}
- Cleanup Temporary Directory ${TMPDIR}
+ Shutdown Process ${RSPAMD_PID}
+ Cleanup Temporary Directory ${TMPDIR}
Log Logs
- [Arguments] ${logfile} ${position}
- ${the_log} ${position} = Read Log From Position ${logfile} ${position}
- Log ${the_log}
- [Return] ${position}
+ [Arguments] ${logfile} ${position}
+ ${the_log} ${position} = Read Log From Position ${logfile} ${position}
+ Log ${the_log}
+ [Return] ${position}
+
+Run Redis
+ ${template} = Get File ${TESTDIR}/configs/redis-server.conf
+ ${config} = Replace Variables ${template}
+ Create File ${TMPDIR}/redis-server.conf ${config}
+ ${result} = Run Process redis-server ${TMPDIR}/redis-server.conf
+ Should Be Equal As Integers ${result.rc} 0
+ ${REDIS_PID} = Get File ${TMPDIR}/redis.pid
+ Run Keyword If '${REDIS_SCOPE}' == 'Test' Set Test Variable ${REDIS_PID}
+ ... ELSE IF '${REDIS_SCOPE}' == 'Suite' Set Suite Variable ${REDIS_PID}
Run Rspamc
- [Arguments] @{args}
- ${result} = Run Process ${RSPAMC} @{args}
- [Return] ${result}
+ [Arguments] @{args}
+ ${result} = Run Process ${RSPAMC} @{args}
+ [Return] ${result}
Run Rspamd
- [Arguments] @{args} &{kw}
- ${tmpdir} = Make Temporary Directory
- Set Directory Ownership ${tmpdir} ${RSPAMD_USER} ${RSPAMD_GROUP}
- Set To Dictionary ${RSPAMD_KEYWORDS} TMPDIR=${tmpdir}
- Update Dictionary ${RSPAMD_KEYWORDS} ${kw}
- :FOR ${i} IN @{args}
- \ Set To Dictionary ${RSPAMD_KEYWORDS} ${i} ${tmpdir}
- Populate Rspamd Config ${CONFIG} ${tmpdir} &{RSPAMD_KEYWORDS}
- ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP} -c ${tmpdir}/rspamd.conf
- ${rspamd_logpos} = Log Logs ${tmpdir}/rspamd.log 0
- Should Be Equal As Integers ${result.rc} 0
- ${rspamd_pid} = Get File ${tmpdir}/rspamd.pid
- [Return] ${tmpdir} ${rspamd_pid} ${rspamd_logpos}
+ [Arguments] @{vargs}
+ ${TMPDIR} = Make Temporary Directory
+ Set Directory Ownership ${TMPDIR} ${RSPAMD_USER} ${RSPAMD_GROUP}
+ ${template} = Get File ${CONFIG}
+ : FOR ${i} IN @{vargs}
+ \ ${newvalue} = Replace Variables ${${i}}
+ \ Set Suite Variable ${${i}} ${newvalue}
+ \ Run Keyword If '${RSPAMD_SCOPE}' == 'Test' Set Test Variable ${${i}} ${newvalue}
+ \ ... ELSE IF '${RSPAMD_SCOPE}' == 'Suite' Set Suite Variable ${${i}} ${newvalue}
+ \ ... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
+ ${config} = Replace Variables ${template}
+ Log ${config}
+ Create File ${TMPDIR}/rspamd.conf ${config}
+ ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP}
+ ... -c ${TMPDIR}/rspamd.conf
+ ${rspamd_logpos} = Log Logs ${TMPDIR}/rspamd.log 0
+ Should Be Equal As Integers ${result.rc} 0
+ ${rspamd_pid} = Get File ${TMPDIR}/rspamd.pid
+ [Return] ${TMPDIR} ${rspamd_pid} ${rspamd_logpos}
Scan Message With Rspamc
- [Arguments] ${msg_file}
- ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} ${msg_file}
- [Return] ${result}
+ [Arguments] ${msg_file}
+ ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} ${msg_file}
+ [Return] ${result}
+
+Sync Fuzzy Storage
+ ${result} = Run Process ${RSPAMADM} control -s ${TMPDIR}/rspamd.sock fuzzy_sync
+ Log ${result.stdout}
+ Follow Rspamd Log
diff --git a/test/functional/lib/vars.py b/test/functional/lib/vars.py
index 78151bd37..316669911 100644
--- a/test/functional/lib/vars.py
+++ b/test/functional/lib/vars.py
@@ -2,6 +2,8 @@ KEY_PVT1 = 'ekd3x36tfa5gd76t6pa8hqif3ott7n1siuux68exbkk7ukscte9y'
KEY_PUB1 = 'm8kneubpcjsb8sbsoj7jy7azj9fdd3xmj63txni86a8ye9ncomny'
LOCAL_ADDR = 'localhost'
PORT_CONTROLLER = 56790
+PORT_FUZZY = 56791
PORT_NORMAL = 56789
+REDIS_PORT = 56379
RSPAMD_GROUP = 'nogroup'
RSPAMD_USER = 'nobody'