From 12945132ac0cab0f712d427113cbc4796779c44b Mon Sep 17 00:00:00 2001 From: Xumin <100666470+StarlightIbuki@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:34:51 +0000 Subject: [PATCH] feat(tests): improve http_mock (#12325) support add dictionaries; fix the behavior when no body is sent --- spec/helpers/http_mock.lua | 1 + spec/helpers/http_mock/template.lua | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/helpers/http_mock.lua b/spec/helpers/http_mock.lua index c1c998a864ae..7d54aac55edf 100644 --- a/spec/helpers/http_mock.lua +++ b/spec/helpers/http_mock.lua @@ -187,6 +187,7 @@ function http_mock.new(listens, routes, opts) listens = listens, routes = routes, directives = directives, + dicts = opts.dicts, init = opts.init, log_opts = log_opts, logs = {}, diff --git a/spec/helpers/http_mock/template.lua b/spec/helpers/http_mock/template.lua index 510cfad8c8c4..fc8c097597e5 100644 --- a/spec/helpers/http_mock/template.lua +++ b/spec/helpers/http_mock/template.lua @@ -24,6 +24,10 @@ events { http { lua_shared_dict mock_logs $(shm_size); +# for dict, size in pairs(dicts or {}) do + lua_shared_dict $(dict) $(size); +# end + init_by_lua_block { # if log_opts.err then -- disable warning of global variable @@ -148,18 +152,20 @@ $(init) # if log_opts.req_body then -- collect body body = ngx.req.get_body_data() -# if log_opts.req_large_body then if not body then local file = ngx.req.get_body_file() if file then +# if log_opts.req_large_body then local f = io.open(file, "r") if f then body = f:read("*a") f:close() end +# else + body = { "body is too large" } +# end -- if log_opts.req_large_body end end -# end -- if log_opts.req_large_body # end -- if log_opts.req_body ngx.ctx.req = { method = method, @@ -238,4 +244,4 @@ $(init) # end -- for location, route in pairs(routes) } } -]] +]] \ No newline at end of file