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

tests(*): http mock support specifying customized init_by_lua_block code #11331

Merged
merged 5 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -160,6 +160,7 @@ function http_mock.new(listens, routes, opts)
listens = listens,
routes = routes,
directives = directives,
init_block = opts.init_block,
log_opts = log_opts,
logs = {},
tls = opts.tls,
Expand Down
11 changes: 7 additions & 4 deletions spec/helpers/http_mock/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ events {
http {
lua_shared_dict mock_logs $(shm_size);

# if log_opts.err then
init_by_lua_block {
# if log_opts.err then
-- disable warning of global variable
local g_meta = getmetatable(_G)
setmetatable(_G, nil)
Expand All @@ -43,7 +43,7 @@ http {

function assert(truthy, err) -- luacheck: ignore
if truthy then
return truthy
return original_assert(truthy, err)
windmgc marked this conversation as resolved.
Show resolved Hide resolved
end

if ngx.ctx then
Expand All @@ -66,9 +66,12 @@ http {
err_patched = true -- luacheck: ignore

setmetatable(_G, g_meta)
# end
# if init_block then
$(init_block)
# end
}

# end
server {
listen 0.0.0.0:$(debug.port);
server_name mock_debug;
Expand Down Expand Up @@ -142,7 +145,7 @@ http {
local method = ngx.req.get_method()
local uri = ngx.var.request_uri
local headers = ngx.req.get_headers(nil, true)


ngx.req.read_body()
local body
Expand Down