]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Rework tests framework to run in a custom environment
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 Jul 2016 12:12:36 +0000 (13:12 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 Jul 2016 12:12:36 +0000 (13:12 +0100)
test/functional/cases/__init__.robot
test/functional/lib/rspamd.py

index 4b95b921733fab54fca63a2cc1d76739f89b3b61..3707f507bce59b909d942bf90fe5ab042e46f1f4 100644 (file)
@@ -6,7 +6,10 @@ Variables       ../lib/vars.py
 *** Keywords ***
 Export Global Variables
   ${TESTDIR} =  Get Test Directory
-  Set Global Variable  ${RSPAMADM}  ${TESTDIR}/../../src/rspamadm/rspamadm
-  Set Global Variable  ${RSPAMC}  ${TESTDIR}/../../src/client/rspamc
-  Set Global Variable  ${RSPAMD}  ${TESTDIR}/../../src/rspamd
+  ${RSPAMADM} =  Get Rspamadm
+  ${RSPAMC} =  Get Rspamc
+  ${RSPAMD} =  Get Rspamd
+  Set Global Variable  ${RSPAMADM}
+  Set Global Variable  ${RSPAMC}
+  Set Global Variable  ${RSPAMD}
   Set Global Variable  ${TESTDIR}
index a90b924bfd86353b52b2481ac3734fc5b2210446..48716f6cf99a1178efb32a5c7eb26f4cce660354 100644 (file)
@@ -37,7 +37,29 @@ def get_process_children(pid):
     return children
 
 def get_test_directory():
-    return os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "../..")
+    return os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "../../")
+
+def get_top_dir():
+    if os.environ.get('RSPAMD_TOPDIR'):
+        return os.environ['RSPAMD_TOPDIR']
+
+    return get_test_directory() + "../../"
+
+def get_rspamd():
+    if os.environ.get('RSPAMD'):
+        return os.environ['RSPAMD']
+    dname = get_top_dir()
+    return dname + "src/rspamd"
+def get_rspamc():
+    if os.environ.get('RSPAMC'):
+        return os.environ['RSPAMC']
+    dname = get_top_dir()
+    return dname + "src/client/rspamc"
+def get_rspamadm():
+    if os.environ.get('RSPAMADM'):
+        return environ['RSPAMADM']
+    dname = get_top_dir()
+    return dname + "src/rspamadm/rspamadm"
 
 def make_temporary_directory():
     return tempfile.mkdtemp()
@@ -71,9 +93,10 @@ def Send_SIGUSR1(pid):
     os.kill(pid, signal.SIGUSR1)
 
 def set_directory_ownership(path, username, groupname):
-    uid=pwd.getpwnam(username).pw_uid
-    gid=grp.getgrnam(groupname).gr_gid
-    os.chown(path, uid, gid)
+    if os.getuid() == 0:
+        uid=pwd.getpwnam(username).pw_uid
+        gid=grp.getgrnam(groupname).gr_gid
+        os.chown(path, uid, gid)
 
 def spamc(addr, port, filename):
     goo = open(filename, 'rb').read()