Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): improve http_mock #12325

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/helpers/http_mock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down
12 changes: 9 additions & 3 deletions spec/helpers/http_mock/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -238,4 +244,4 @@ $(init)
# end -- for location, route in pairs(routes)
}
}
]]
]]
Loading