diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-30 09:40:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-30 09:40:41 +0100 |
commit | e781ebaa06cf528fb62bff240dfecf9487862ab4 (patch) | |
tree | 8a53779617e06a2ad50c9c36a27ad8ae5dc71485 | |
parent | e23501d4d93d582c20bb521fd16ae07dd854c3c4 (diff) | |
parent | e3a301a85d355a7f559173b88613fb4da5fbd016 (diff) | |
download | rspamd-e781ebaa06cf528fb62bff240dfecf9487862ab4.tar.gz rspamd-e781ebaa06cf528fb62bff240dfecf9487862ab4.zip |
Merge pull request #686 from fatalbanana/robot
Minor tweaks for test suite
-rw-r--r-- | test/functional/cases/general.robot | 6 | ||||
-rw-r--r-- | test/functional/cases/lua.robot | 3 | ||||
-rw-r--r-- | test/functional/cases/statistics.robot | 48 | ||||
-rw-r--r-- | test/functional/lib/rspamd.py | 21 | ||||
-rw-r--r-- | test/functional/lib/rspamd.robot | 10 |
5 files changed, 42 insertions, 46 deletions
diff --git a/test/functional/cases/general.robot b/test/functional/cases/general.robot index 4016b9a6a..aa146b4a9 100644 --- a/test/functional/cases/general.robot +++ b/test/functional/cases/general.robot @@ -13,13 +13,11 @@ ${RSPAMD_SCOPE} Suite *** Test Cases *** GTUBE ${result} = Scan Message With Rspamc ${GTUBE} - Follow Rspamd Log - Should Contain ${result.stdout} GTUBE ( + Check Rspamc ${result} GTUBE ( GTUBE - Encrypted ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} --key ${KEY_PUB1} ${GTUBE} - Follow Rspamd Log - Should Contain ${result.stdout} GTUBE ( + Check Rspamc ${result} GTUBE ( GTUBE - Scan File feature ${result} = Scan File ${LOCAL_ADDR} ${PORT_NORMAL} ${GTUBE} diff --git a/test/functional/cases/lua.robot b/test/functional/cases/lua.robot index b8005cd8f..46dd15ea0 100644 --- a/test/functional/cases/lua.robot +++ b/test/functional/cases/lua.robot @@ -26,6 +26,5 @@ Flags Dependencies [Setup] Lua Setup ${TESTDIR}/lua/deps.lua ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} DEP10 + Check Rspamc ${result} DEP10 [Teardown] Generic Teardown diff --git a/test/functional/cases/statistics.robot b/test/functional/cases/statistics.robot index d9df49813..6d0218b56 100644 --- a/test/functional/cases/statistics.robot +++ b/test/functional/cases/statistics.robot @@ -21,21 +21,17 @@ Statistics Setup Sqlite Learn - Keyed, siphash [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=siphash STATS_KEY=${KEY_PVT1} ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE} - Should Contain ${result.stdout} success = true - Follow Rspamd Log + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_SPAM + Check Rspamc ${result} BAYES_SPAM [Teardown] Generic Teardown Sqlite Learn - Keyed, xxhash [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1} ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_SPAM + Check Rspamc ${result} BAYES_SPAM [Teardown] Generic Teardown Sqlite Learn - Broken Stats Directory @@ -49,51 +45,39 @@ Sqlite Learn - Empty part [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1} Set Test Variable ${MESSAGE} ${TESTDIR}/messages/empty_part.eml ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_SPAM + Check Rspamc ${result} BAYES_SPAM [Teardown] Generic Teardown Sqlite Relearn [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1} ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_SPAM + Check Rspamc ${result} BAYES_SPAM ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_ham ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_HAM + Check Rspamc ${result} BAYES_HAM [Teardown] Generic Teardown Mmap Learn [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=mmap STATS_HASH=compat STATS_KEY=${KEY_PVT1} ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_SPAM + Check Rspamc ${result} BAYES_SPAM [Teardown] Generic Teardown Mmap Relearn [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=mmap STATS_HASH=compat STATS_KEY=${KEY_PVT1} ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_SPAM + Check Rspamc ${result} BAYES_SPAM ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_ham ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} success = true + Check Rspamc ${result} ${result} = Scan Message With Rspamc ${MESSAGE} - Follow Rspamd Log - Should Contain ${result.stdout} BAYES_HAM + Check Rspamc ${result} BAYES_HAM [Teardown] Generic Teardown diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py index 998eb6960..93ec4c430 100644 --- a/test/functional/lib/rspamd.py +++ b/test/functional/lib/rspamd.py @@ -6,9 +6,16 @@ import shutil import signal import socket import string +import sys import tempfile import time -import urllib2 + +if sys.version_info > (3,): + long = int +try: + from urllib.request import urlopen +except: + from urllib2 import urlopen def cleanup_temporary_directory(directory): shutil.rmtree(directory) @@ -41,9 +48,7 @@ def read_log_from_position(filename, offset): return [goo, size+offset] def scan_file(addr, port, filename): - req = urllib2.Request("http://%s:%s/symbols?%s" % (addr, port, filename)) - response = urllib2.urlopen(req) - return response.read() + return str(urlopen("http://%s:%s/symbols?%s" % (addr, port, filename)).read()) def Send_SIGUSR1(pid): pid = int(pid) @@ -56,13 +61,15 @@ def set_directory_ownership(path, username, groupname): def spamc(addr, port, filename): goo = open(filename, 'rb').read() - length = len(goo) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((addr, port)) - s.send("SYMBOLS SPAMC/1.0\r\nContent-length: %s\r\n\r\n%s" % (length, goo)) + s.send(b"SYMBOLS SPAMC/1.0\r\nContent-length: ") + s.send(str(len(goo)).encode('utf-8')) + s.send(b"\r\n\r\n") + s.send(goo) s.shutdown(socket.SHUT_WR) r = s.recv(2048) - return r + return r.decode('utf-8') def update_dictionary(a, b): a.update(b) diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot index a5ddca20e..b6180d40d 100644 --- a/test/functional/lib/rspamd.robot +++ b/test/functional/lib/rspamd.robot @@ -4,6 +4,15 @@ Library OperatingSystem Library Process *** Keywords *** +Check Rspamc + [Arguments] ${result} @{args} + ${arglen} = Get Length ${args} + ${expected_output} = Set Variable If ${arglen} < 1 success = true @{args}[0] + ${expected_rc} = Set Variable If ${arglen} < 2 0 @{args}[1] + Follow Rspamd Log + Should Contain ${result.stdout} ${expected_output} + Should Be Equal As Integers ${result.rc} ${expected_rc} + Export Rspamd Vars To Suite [Arguments] ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID} Set Suite Variable ${TMPDIR} @@ -41,7 +50,6 @@ Log Logs Run Rspamc [Arguments] @{args} ${result} = Run Process ${RSPAMC} @{args} - Should Be Equal As Integers ${result.rc} 0 [Return] ${result} Run Rspamd |