commit 3a6074d: [Test] Use Robot Framework native IF
Andrew Lewis
nerf at judo.za.org
Tue Oct 3 15:28:03 UTC 2023
Author: Andrew Lewis
Date: 2023-10-02 15:23:25 +0200
URL: https://github.com/rspamd/rspamd/commit/3a6074d1ddca799721b396ee58844112174161fe (refs/pull/4625/head)
[Test] Use Robot Framework native IF
- Since 4.0 (March 2021)
---
.../cases/001_merged/160_antivirus.robot | 4 +-
test/functional/cases/110_statistics/lib.robot | 8 +-
test/functional/cases/116_dkim.robot | 4 +-
test/functional/cases/120_fuzzy/lib.robot | 8 +-
test/functional/cases/200_luacheck.robot | 4 +-
.../cases/210_clickhouse/001_migration.robot | 14 ++-
test/functional/lib/rspamd.robot | 112 ++++++++++++++-------
7 files changed, 109 insertions(+), 45 deletions(-)
diff --git a/test/functional/cases/001_merged/160_antivirus.robot b/test/functional/cases/001_merged/160_antivirus.robot
index 166bdb6a8..0870ba6a8 100644
--- a/test/functional/cases/001_merged/160_antivirus.robot
+++ b/test/functional/cases/001_merged/160_antivirus.robot
@@ -129,7 +129,9 @@ Run Dummy
${process} = Start Process @{varargs}
${pid} = Get From List ${varargs} -1
${pass} = Run Keyword And Return Status Wait Until Created ${pid}
- Run Keyword If ${pass} Return From Keyword
+ IF ${pass}
+ Return From Keyword
+ END
Wait For Process ${process}
${res} = Get Process Result ${process}
Log To Console ${res.stdout}
diff --git a/test/functional/cases/110_statistics/lib.robot b/test/functional/cases/110_statistics/lib.robot
index 794a05952..c6fad2b2f 100644
--- a/test/functional/cases/110_statistics/lib.robot
+++ b/test/functional/cases/110_statistics/lib.robot
@@ -38,10 +38,14 @@ Learn Test
Set Suite Variable ${RSPAMD_STATS_LEARNTEST} 1
Relearn Test
- Run Keyword If ${RSPAMD_STATS_LEARNTEST} == 0 Fail "Learn test was not run"
+ IF ${RSPAMD_STATS_LEARNTEST} == 0
+ Fail "Learn test was not run"
+ END
${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} learn_ham ${MESSAGE_SPAM}
Check Rspamc ${result}
Scan File ${MESSAGE_SPAM}
${pass} = Run Keyword And Return Status Expect Symbol BAYES_HAM
- Run Keyword If ${pass} Pass Execution What Me Worry
+ IF ${pass}
+ Pass Execution What Me Worry
+ END
Do Not Expect Symbol BAYES_SPAM
diff --git a/test/functional/cases/116_dkim.robot b/test/functional/cases/116_dkim.robot
index e710f659d..5c1005c28 100644
--- a/test/functional/cases/116_dkim.robot
+++ b/test/functional/cases/116_dkim.robot
@@ -44,7 +44,9 @@ DKIM Sign
Set Suite Variable ${RAN_SIGNTEST} 1
DKIM Self Verify
- Run Keyword If ${RAN_SIGNTEST} == 0 Fail "Sign test was not run"
+ IF ${RAN_SIGNTEST} == 0
+ Fail "Sign test was not run"
+ END
Scan File ${SIGNED_MESSAGE}
Expect Symbol R_DKIM_ALLOW
diff --git a/test/functional/cases/120_fuzzy/lib.robot b/test/functional/cases/120_fuzzy/lib.robot
index 96ebc8aa5..02e0a0af5 100644
--- a/test/functional/cases/120_fuzzy/lib.robot
+++ b/test/functional/cases/120_fuzzy/lib.robot
@@ -53,7 +53,9 @@ Fuzzy Add Test
Fuzzy Delete Test
[Arguments] ${message}
- Run Keyword If ${RSPAMD_FUZZY_ADD_${message}} == 0 Fail "Fuzzy Add was not run"
+ IF ${RSPAMD_FUZZY_ADD_${message}} == 0
+ Fail "Fuzzy Add was not run"
+ END
${result} = Run Rspamc -h ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER} -f ${RSPAMD_FLAG1_NUMBER} fuzzy_del
... ${message}
Check Rspamc ${result}
@@ -63,7 +65,9 @@ Fuzzy Delete Test
Fuzzy Fuzzy Test
[Arguments] ${message}
- Run Keyword If ${RSPAMD_FUZZY_ADD_${message}} != 1 Fail "Fuzzy Add was not run"
+ IF ${RSPAMD_FUZZY_ADD_${message}} != 1
+ Fail "Fuzzy Add was not run"
+ END
@{path_info} = Path Splitter ${message}
@{fuzzy_files} = List Files In Directory ${pathinfo}[0] pattern=${pathinfo}[1].fuzzy* absolute=1
FOR ${i} IN @{fuzzy_files}
diff --git a/test/functional/cases/200_luacheck.robot b/test/functional/cases/200_luacheck.robot
index d2fe18628..a38fe083e 100644
--- a/test/functional/cases/200_luacheck.robot
+++ b/test/functional/cases/200_luacheck.robot
@@ -4,5 +4,7 @@ Library Process
*** Test Cases ***
Lua Check
${result} = Run Process luacheck -q --no-color . cwd=${TOPDIR}
- Run Keyword If ${result.rc} != 0 Log ${result.stdout}
+ IF ${result.rc} != 0
+ Log ${result.stdout}
+ END
Should Be Equal As Integers ${result.rc} 0 msg=${result.stdout} values=false
diff --git a/test/functional/cases/210_clickhouse/001_migration.robot b/test/functional/cases/210_clickhouse/001_migration.robot
index b1648b090..2153c234c 100644
--- a/test/functional/cases/210_clickhouse/001_migration.robot
+++ b/test/functional/cases/210_clickhouse/001_migration.robot
@@ -63,7 +63,9 @@ Clickhouse Setup
Set Directory Ownership ${RSPAMD_TMPDIR}/clickhouse clickhouse clickhouse
${result} = Run Process su -s /bin/sh clickhouse -c
... clickhouse-server --daemon --config-file\=${RSPAMD_TMPDIR}/clickhouse-config.xml --pid-file\=${RSPAMD_TMPDIR}/clickhouse/clickhouse.pid
- Run Keyword If ${result.rc} != 0 Log ${result.stderr}
+ IF ${result.rc} != 0
+ Log ${result.stderr}
+ END
Should Be Equal As Integers ${result.rc} 0
Wait Until Keyword Succeeds 5 sec 50 ms TCP Connect localhost ${CLICKHOUSE_PORT}
Set Suite Variable ${RSPAMD_TMPDIR} ${RSPAMD_TMPDIR}
@@ -79,7 +81,11 @@ Prepare rspamd
&{d} = Run Rspamd CONFIG=${RSPAMD_TESTDIR}/configs/clickhouse.conf TMPDIR=${RSPAMD_TMPDIR}
${keys} = Get Dictionary Keys ${d}
FOR ${i} IN @{keys}
- Run Keyword If '${RSPAMD_SCOPE}' == 'Suite' Set Suite Variable ${${i}} ${d}[${i}]
- ... ELSE IF '${RSPAMD_SCOPE}' == 'Test' Set Test Variable ${${i}} ${d}[${i}]
- ... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
+ IF '${RSPAMD_SCOPE}' == 'Suite'
+ Set Suite Variable ${${i}} ${d}[${i}]
+ ELSE IF '${RSPAMD_SCOPE}' == 'Test'
+ Set Test Variable ${${i}} ${d}[${i}]
+ ELSE
+ Fail 'RSPAMD_SCOPE must be Test or Suite'
+ END
END
diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot
index 7d95287cf..27dad96ee 100644
--- a/test/functional/lib/rspamd.robot
+++ b/test/functional/lib/rspamd.robot
@@ -17,32 +17,48 @@ Check Pidfile
Check Rspamc
[Arguments] ${result} @{args} &{kwargs}
- Run Keyword If ${result.rc} != 0 Log ${result.stderr}
+ IF ${result.rc} != 0
+ Log ${result.stderr}
+ END
${has_rc} = Evaluate 'rc' in $kwargs
${inverse} = Evaluate 'inverse' in $kwargs
${re} = Evaluate 're' in $kwargs
${rc} = Set Variable If ${has_rc} == True ${kwargs}[rc] 0
FOR ${i} IN @{args}
- Run Keyword If ${re} == True Check Rspamc Match Regexp ${result.stdout} ${i} ${inverse}
- ... ELSE Check Rspamc Match String ${result.stdout} ${i} ${inverse}
+ IF ${re} == True
+ Check Rspamc Match Regexp ${result.stdout} ${i} ${inverse}
+ ELSE
+ Check Rspamc Match String ${result.stdout} ${i} ${inverse}
+ END
+ END
+ IF @{args} == @{EMPTY}
+ Check Rspamc Match Default ${result.stdout} ${inverse}
END
- Run Keyword If @{args} == @{EMPTY} Check Rspamc Match Default ${result.stdout} ${inverse}
Should Be Equal As Integers ${result.rc} ${rc}
Check Rspamc Match Default
[Arguments] ${subject} ${inverse}
- Run Keyword If ${inverse} == False Should Contain ${subject} success = true
- ... ELSE Should Not Contain ${subject} success = true
+ IF ${inverse} == False
+ Should Contain ${subject} success = true
+ ELSE
+ Should Not Contain ${subject} success = true
+ END
Check Rspamc Match Regexp
[Arguments] ${subject} ${re} ${inverse}
- Run Keyword If ${inverse} == False Should Match Regexp ${subject} ${re}
- ... ELSE Should Not Match Regexp ${subject} ${re}
+ IF ${inverse} == False
+ Should Match Regexp ${subject} ${re}
+ ELSE
+ Should Not Match Regexp ${subject} ${re}
+ END
Check Rspamc Match String
[Arguments] ${subject} ${str} ${inverse}
- Run Keyword If ${inverse} == False Should Contain ${subject} ${str}
- ... ELSE Should Not Contain ${subject} ${str}
+ IF ${inverse} == False
+ Should Contain ${subject} ${str}
+ ELSE
+ Should Not Contain ${subject} ${str}
+ END
Do Not Expect Symbol
[Arguments] ${symbol}
@@ -140,16 +156,23 @@ Expect Symbol With Score And Exact Options
Export Rspamd Variables To Environment
&{all_vars} = Get Variables no_decoration=True
FOR ${k} ${v} IN &{all_vars}
- Run Keyword If '${k}'.startswith("RSPAMD_") Set Environment Variable ${k} ${v}
+ IF '${k}'.startswith("RSPAMD_")
+ Set Environment Variable ${k} ${v}
+ END
END
Export Scoped Variables
[Arguments] ${scope} &{vars}
FOR ${k} ${v} IN &{vars}
- Run Keyword If '${scope}' == 'Test' Set Test Variable ${${k}} ${v}
- ... ELSE IF '${scope}' == 'Suite' Set Suite Variable ${${k}} ${v}
- ... ELSE IF '${scope}' == 'Global' Set Global Variable ${${k}} ${v}
- ... ELSE Fail message="Don't know what to do with scope: ${scope}"
+ IF '${scope}' == 'Test'
+ Set Test Variable ${${k}} ${v}
+ ELSE IF '${scope}' == 'Suite'
+ Set Suite Variable ${${k}} ${v}
+ ELSE IF '${scope}' == 'Global'
+ Set Global Variable ${${k}} ${v}
+ ELSE
+ Fail message="Don't know what to do with scope: ${scope}"
+ END
END
Log does not contain segfault record
@@ -160,7 +183,9 @@ Redis HSET
[Arguments] ${hash} ${key} ${value}
${result} = Run Process redis-cli -h ${RSPAMD_REDIS_ADDR} -p ${RSPAMD_REDIS_PORT}
... HSET ${hash} ${key} ${value}
- Run Keyword If ${result.rc} != 0 Log ${result.stderr}
+ IF ${result.rc} != 0
+ Log ${result.stderr}
+ END
Log ${result.stdout}
Should Be Equal As Integers ${result.rc} 0
@@ -168,7 +193,9 @@ Redis SET
[Arguments] ${key} ${value}
${result} = Run Process redis-cli -h ${RSPAMD_REDIS_ADDR} -p ${RSPAMD_REDIS_PORT}
... SET ${key} ${value}
- Run Keyword If ${result.rc} != 0 Log ${result.stderr}
+ IF ${result.rc} != 0
+ Log ${result.stderr}
+ END
Log ${result.stdout}
Should Be Equal As Integers ${result.rc} 0
@@ -192,9 +219,9 @@ Rspamd Redis Setup
Rspamd Setup
Rspamd Teardown
- # Robot Framework 4.0
- #Run Keyword If '${CONTROLLER_ERRORS}' == 'True' Run Keyword And Warn On Failure Check Controller Errors
- Run Keyword If '${CONTROLLER_ERRORS}' == 'True' Check Controller Errors
+ IF '${CONTROLLER_ERRORS}' == 'True'
+ Run Keyword And Warn On Failure Check Controller Errors
+ END
Shutdown Process With Children ${RSPAMD_PID}
Save Run Results ${RSPAMD_TMPDIR} configdump.stdout configdump.stderr rspamd.stderr rspamd.stdout rspamd.conf rspamd.log redis.log clickhouse-config.xml
Log does not contain segfault record
@@ -212,7 +239,9 @@ Run Redis
Create File ${RSPAMD_TMPDIR}/redis-server.conf ${config}
Log ${config}
${result} = Run Process redis-server ${RSPAMD_TMPDIR}/redis-server.conf
- Run Keyword If ${result.rc} != 0 Log ${result.stderr}
+ IF ${result.rc} != 0
+ Log ${result.stderr}
+ END
Should Be Equal As Integers ${result.rc} 0
Wait Until Keyword Succeeds 5x 1 sec Check Pidfile ${RSPAMD_TMPDIR}/redis.pid timeout=0.5s
Wait Until Keyword Succeeds 5x 1 sec Redis Check ${RSPAMD_REDIS_ADDR} ${RSPAMD_REDIS_PORT}
@@ -240,8 +269,11 @@ Run Rspamd
... env:ASAN_OPTIONS=quarantine_size_mb=2048:malloc_context_size=20:fast_unwind_on_malloc=0:log_path=${RSPAMD_TMPDIR}/rspamd-asan
# We need to send output to files (or discard output) to avoid hanging Robot
... stdout=${RSPAMD_TMPDIR}/configdump.stdout stderr=${RSPAMD_TMPDIR}/configdump.stderr
- ${configdump} = Run Keyword If ${result.rc} == 0 Get File ${RSPAMD_TMPDIR}/configdump.stdout encoding_errors=ignore
- ... ELSE Get File ${RSPAMD_TMPDIR}/configdump.stderr encoding_errors=ignore
+ IF ${result.rc} == 0
+ ${configdump} = Get File ${RSPAMD_TMPDIR}/configdump.stdout encoding_errors=ignore
+ ELSE
+ ${configdump} = Get File ${RSPAMD_TMPDIR}/configdump.stderr encoding_errors=ignore
+ END
Log ${configdump}
# Fix directory ownership (maybe do this somewhere else)
@@ -287,13 +319,18 @@ Run Nginx
Create File ${RSPAMD_TMPDIR}/nginx.conf ${config}
Log ${config}
${result} = Run Process nginx -c ${RSPAMD_TMPDIR}/nginx.conf
- Run Keyword If ${result.rc} != 0 Log ${result.stderr}
+ IF ${result.rc} != 0
+ Log ${result.stderr}
+ END
Should Be Equal As Integers ${result.rc} 0
Wait Until Keyword Succeeds 10x 1 sec Check Pidfile ${RSPAMD_TMPDIR}/nginx.pid timeout=0.5s
Wait Until Keyword Succeeds 5x 1 sec TCP Connect ${NGINX_ADDR} ${NGINX_PORT}
${NGINX_PID} = Get File ${RSPAMD_TMPDIR}/nginx.pid
- Run Keyword If '${NGINX_SCOPE}' == 'Test' Set Test Variable ${NGINX_PID}
- ... ELSE IF '${NGINX_SCOPE}' == 'Suite' Set Suite Variable ${NGINX_PID}
+ IF '${NGINX_SCOPE}' == 'Test'
+ Set Test Variable ${NGINX_PID}
+ ELSE IF '${NGINX_SCOPE}' == 'Suite'
+ Set Suite Variable ${NGINX_PID}
+ END
${nginx_log} = Get File ${RSPAMD_TMPDIR}/nginx.log
Log ${nginx_log}
@@ -318,24 +355,31 @@ Scan Message With Rspamc
Sync Fuzzy Storage
[Arguments] @{vargs}
${len} = Get Length ${vargs}
- ${result} = Run Keyword If $len == 0 Run Process ${RSPAMADM} control -s
- ... ${RSPAMD_TMPDIR}/rspamd.sock fuzzy_sync
- ... ELSE Run Process ${RSPAMADM} control -s ${vargs}[0]/rspamd.sock
- ... fuzzy_sync
+ IF $len == 0
+ ${result} = Run Process ${RSPAMADM} control -s
+ ... ${RSPAMD_TMPDIR}/rspamd.sock fuzzy_sync
+ ELSE
+ Run Process ${RSPAMADM} control -s ${vargs}[0]/rspamd.sock
+ ... fuzzy_sync
+ END
Log ${result.stdout}
Sleep 0.1s Try give fuzzy storage time to sync
Run Dummy Http
${fileExists} = File Exists /tmp/dummy_http.pid
- ${http_pid} = Run Keyword If ${fileExists} is True Get File /tmp/dummy_http.pid
- Run Keyword If ${fileExists} is True Shutdown Process With Children ${http_pid}
+ IF ${fileExists} is True
+ ${http_pid} = Get File /tmp/dummy_http.pid
+ Shutdown Process With Children ${http_pid}
+ END
${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_http.py -pf /tmp/dummy_http.pid
Wait Until Created /tmp/dummy_http.pid timeout=2 second
Run Dummy Https
${fileExists} = File Exists /tmp/dummy_https.pid
- ${http_pid} = Run Keyword If ${fileExists} is True Get File /tmp/dummy_https.pid
- Run Keyword If ${fileExists} is True Shutdown Process With Children ${http_pid}
+ IF ${fileExists} is True
+ ${http_pid} = Get File /tmp/dummy_https.pid
+ Shutdown Process With Children ${http_pid}
+ END
${result} = Start Process ${RSPAMD_TESTDIR}/util/dummy_http.py
... -c ${RSPAMD_TESTDIR}/util/server.pem -k ${RSPAMD_TESTDIR}/util/server.pem
... -pf /tmp/dummy_https.pid -p 18081
More information about the Commits
mailing list