[OpenResty] Lua Project TestCase Problem

20 views
Skip to first unread message

许亚东

unread,
May 7, 2025, 6:01:31 AMMay 7
to openresty
"Dear experts, I'm using Busted to test my OpenResty Lua project, which uses MySQL via openresty/lua-resty-mysql. Here is my code structure:

Test target: res.lua
Test case: test_res.lua
NGINX mock: mock_ngx.lua
When executing busted test/utils/test_res.lua, it fails with the error:

utils.res mysql init  
/usr/local/openresty/lualib/resty/core/base.lua:80: loop or previous error loading module 'socket'  

I suspect this is due to an incomplete mock of ngx.socket, but I don't know how to fix it.

​Questions:​​

1. Can Busted be used for testing OpenResty + Lua projects, or is there a better approach?
2. Does anyone have a complete ngx mock example that I can use? Thank you very much!"
test_res.lua
mock_ngx.lua
res.lua
Reply all
Reply to author
Forward
0 new messages