Skip to content

Commit cd1e383

Browse files
themilchenkosergos
authored andcommitted
tests: refactor log test
Global log level settings were declared that were only used in one test, but all tests in group were re-run because of it. This patch fixes it and update config with its log level only for this test.
1 parent 51d4c7b commit cd1e383

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

test/integration/httpd_role_test.lua

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ local http_client = require('http.client').new()
99

1010
local helpers = require('test.helpers')
1111

12-
local LOG_LEVEL = {
12+
local LOG_LEVELS = {
1313
INFO = 5,
1414
VERBOSE = 6,
1515
DEBUG = 7,
1616
}
1717

1818
local g = t.group(nil, t.helpers.matrix({
1919
use_tls = {true, false},
20-
log_level = {
21-
LOG_LEVEL.INFO,
22-
LOG_LEVEL.VERBOSE,
23-
LOG_LEVEL.DEBUG,
24-
},
2520
}))
2621

2722
local ssl_data_dir = fio.abspath(fio.pathjoin(helpers.get_testdir_path(), "ssl_data"))
@@ -103,8 +98,6 @@ g.before_each(function(cg)
10398
cfg = tls_config
10499
end
105100

106-
cfg.log = {level = cg.params.log_level}
107-
108101
local config_file = treegen.write_file(dir, 'config.yaml',
109102
yaml.encode(cfg))
110103
local opts = {config_file = config_file, chdir = dir}
@@ -188,31 +181,41 @@ g.test_keep_existing_server_routes_on_config_reload = function(cg)
188181
t.assert_equals(resp.body, 'pong once')
189182
end
190183

191-
g.test_log_requests = function(cg)
192-
t.skip_if(cg.params.use_tls)
193-
194-
local function make_request(address)
195-
local resp = http_client:get(string.format('http://%s/ping', address))
196-
t.assert_equals(resp.status, 200, 'response not 200')
197-
end
184+
for log_name, log_lvl in pairs(LOG_LEVELS) do
185+
g.before_test('test_log_requests_' .. string.lower(log_name), function(cg)
186+
local cfg = table.copy(config)
187+
cfg.log = {level = log_lvl}
188+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(cfg))
189+
local _, err = cg.server:eval("require('config'):reload()")
190+
t.assert_not(err)
191+
end)
192+
193+
g['test_log_requests_' .. string.lower(log_name)] = function(cg)
194+
t.skip_if(cg.params.use_tls)
195+
196+
local function make_request(address)
197+
local resp = http_client:get(string.format('http://%s/ping', address))
198+
t.assert_equals(resp.status, 200, 'response not 200')
199+
end
198200

199-
local function assert_should_log(expected)
200-
local grep_res = cg.server:grep_log('GET /ping', math.huge)
201-
if expected then
202-
t.assert(grep_res)
203-
else
204-
t.assert_not(grep_res)
201+
local function assert_should_log(expected)
202+
local grep_res = cg.server:grep_log('GET /ping', math.huge)
203+
if expected then
204+
t.assert(grep_res)
205+
else
206+
t.assert_not(grep_res)
207+
end
205208
end
206-
end
207209

208-
local log_level = tonumber(cg.params.log_level)
210+
local log_level = tonumber(log_lvl)
209211

210-
make_request('localhost:13002')
211-
assert_should_log(log_level >= LOG_LEVEL.DEBUG)
212+
make_request('localhost:13002')
213+
assert_should_log(log_level >= LOG_LEVELS.DEBUG)
212214

213-
make_request('localhost:13001')
214-
assert_should_log(log_level >= LOG_LEVEL.VERBOSE)
215+
make_request('localhost:13001')
216+
assert_should_log(log_level >= LOG_LEVELS.VERBOSE)
215217

216-
make_request('localhost:13000')
217-
assert_should_log(log_level >= LOG_LEVEL.INFO)
218+
make_request('localhost:13000')
219+
assert_should_log(log_level >= LOG_LEVELS.INFO)
220+
end
218221
end

0 commit comments

Comments
 (0)