aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-10-07 16:17:08 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-10-07 16:17:08 +0300
commit9f66eaff09303e218e8fe675b68c0eafd19f8020 (patch)
tree3c10235dbbd4462e0d508e131f28e1dbbe06398c
parentcc8135a1825c8efc9b3f0d1189f665d7b1b9405f (diff)
downloadawall-9f66eaff09303e218e8fe675b68c0eafd19f8020.tar.bz2
awall-9f66eaff09303e218e8fe675b68c0eafd19f8020.tar.xz
test: filter-limit: refactor
-rw-r--r--test/mandatory/filter-limit.lua86
1 files changed, 45 insertions, 41 deletions
diff --git a/test/mandatory/filter-limit.lua b/test/mandatory/filter-limit.lua
index 9eb1cfb..0b150c0 100644
--- a/test/mandatory/filter-limit.lua
+++ b/test/mandatory/filter-limit.lua
@@ -1,48 +1,52 @@
-update = require('awall.util').update
+util = require('awall.util')
json = require('cjson')
res = {}
-function add(limit_type, base)
- for _, count in ipairs{1, 30} do
- for _, limit in ipairs{
- count,
- {count=count},
- {count=count, log=false},
- {count=count, log='none'}
- } do
- for _, name in ipairs{
- false, type(limit) == 'table' and count == 1 and 'foo' or nil
- } do
- for _, addr in ipairs{false, name and 'dest' or nil} do
- for _, no_update in ipairs{false, name or nil} do
- local upd
- if no_update then upd = false end
- for _, log in ipairs{false, true, 'none'} do
- for _, action in ipairs{false, 'pass'} do
- if not (count == 30 and log and action) then
- table.insert(
- res,
- update(
- {
- [limit_type..'-limit']=type(limit) == 'table' and update(
- {
- name=name or nil,
- addr=addr or nil,
- update=upd
- },
- limit
- ) or limit,
- log=log or nil,
- action=action or nil
- },
- base or {}
- )
- )
- end
- end
- end
- end
+function add(limit_type, filter)
+
+ for _, high_rate in ipairs{false, true} do
+
+ local function add_limit(limit)
+ for _, log in ipairs{false, true, 'none'} do
+ for _, action in ipairs{false, 'pass'} do
+ if not (high_rate and log and action) then
+ table.insert(
+ res,
+ util.update(
+ {
+ [limit_type..'-limit']=util.copy(limit),
+ log=log or nil,
+ action=action or nil
+ },
+ filter or {}
+ )
+ )
+ end
+ end
+ end
+ end
+
+ local count = high_rate and 30 or 1
+ add_limit(count)
+
+ for _, log in ipairs{true, false, 'none'} do
+ local limit = {count=count}
+ if log ~= true then limit.log = log end
+
+ add_limit(limit)
+
+ if not high_rate then
+ limit.name = 'foo'
+
+ for _, addr in ipairs{false, 'dest'} do
+ limit.addr = addr or nil
+
+ limit.update = nil
+ add_limit(limit)
+
+ limit.update = false
+ add_limit(limit)
end
end
end