@@ -9,7 +9,20 @@ local http_client = require('http.client').new()
99
1010local helpers = require (' test.helpers' )
1111
12- local g = t .group (nil , t .helpers .matrix ({use_tls = {true , false }}))
12+ local LOG_LEVEL = {
13+ INFO = 5 ,
14+ VERBOSE = 6 ,
15+ DEBUG = 7 ,
16+ }
17+
18+ local g = t .group (nil , t .helpers .matrix ({
19+ use_tls = {true , false },
20+ log_level = {
21+ LOG_LEVEL .INFO ,
22+ LOG_LEVEL .VERBOSE ,
23+ LOG_LEVEL .DEBUG ,
24+ },
25+ }))
1326
1427local ssl_data_dir = fio .abspath (fio .pathjoin (helpers .get_testdir_path (), " ssl_data" ))
1528
@@ -36,10 +49,16 @@ local config = {
3649 [' roles.httpd' ] = {
3750 default = {
3851 listen = 13000 ,
52+ log_requests = ' info' ,
3953 },
4054 additional = {
4155 listen = 13001 ,
42- }
56+ log_requests = ' verbose' ,
57+ },
58+ additional_debug = {
59+ listen = 13002 ,
60+ log_requests = ' debug' ,
61+ },
4362 },
4463 [' test.mocks.mock_role' ] = {
4564 {
@@ -49,6 +68,10 @@ local config = {
4968 id = 2 ,
5069 name = ' additional' ,
5170 },
71+ {
72+ id = 3 ,
73+ name = ' additional_debug' ,
74+ }
5275 },
5376 },
5477 instances = {
@@ -80,6 +103,8 @@ g.before_each(function(cg)
80103 cfg = tls_config
81104 end
82105
106+ cfg .log = {level = cg .params .log_level }
107+
83108 local config_file = treegen .write_file (dir , ' config.yaml' ,
84109 yaml .encode (cfg ))
85110 local opts = {config_file = config_file , chdir = dir }
@@ -146,3 +171,32 @@ g.test_change_server_addr_on_the_run = function(cg)
146171 t .assert_equals (resp .status , 200 , ' response not 200' )
147172 t .assert_equals (resp .body , ' pong' )
148173end
174+
175+ g .test_log_requests = function (cg )
176+ t .skip_if (cg .params .use_tls )
177+
178+ local function make_request (address )
179+ local resp = http_client :get (string.format (' http://%s/ping' , address ))
180+ t .assert_equals (resp .status , 200 , ' response not 200' )
181+ end
182+
183+ local function assert_should_log (expected )
184+ local grep_res = cg .server :grep_log (' GET /ping' , math.huge )
185+ if expected then
186+ t .assert (grep_res )
187+ else
188+ t .assert_not (grep_res )
189+ end
190+ end
191+
192+ local log_level = tonumber (cg .params .log_level )
193+
194+ make_request (' localhost:13002' )
195+ assert_should_log (log_level >= LOG_LEVEL .DEBUG )
196+
197+ make_request (' localhost:13001' )
198+ assert_should_log (log_level >= LOG_LEVEL .VERBOSE )
199+
200+ make_request (' localhost:13000' )
201+ assert_should_log (log_level >= LOG_LEVEL .INFO )
202+ end
0 commit comments