Open turbo opened 5 years ago
hello, I also ran into this issue while writing unit test with resty cli and busted test framework,here is a minimial case: prepare two unit test file spec/ dir simply require resty-shell lib and busted runner: spec/1_spec.lua
describe("ut 1", function()
it("ut 1", function()
require("resty.shell")
end)
end)
spec/2_spec.lua
describe("ut 2", function()
it("ut 2", function()
require("resty.shell")
end)
end)
spec/busted_runner.lua
setmetatable(_G, nil)
require 'busted.runner'({standalone = false })
run the two test file with resty cli as follow:
/usr/local/openresty/bin/resty spec/busted_runner.lua -v spec/
the second file 2_spec.lua aborted with error:
[gerrard@gerrard ~]$ /usr/local/openresty/bin/resty spec/busted_runner.lua -v spec/
●✱
1 success / 0 failures / 1 error / 0 pending : 0.001975 seconds
Error → spec/2_spec.lua @ 16
ut 2 ut 2
/usr/local/openresty/lualib/ngx/pipe.lua:500: cannot change a protected metatable
stack traceback:
/usr/local/openresty/lualib/ngx/pipe.lua:500: in main chunk
envirment on centos7:
[gerrard@gerrard ~]$ busted --version
2.0.0-0
[gerrard@gerrard ~]$ /usr/local/openresty/bin/resty -v
resty 0.23
nginx version: openresty/1.15.8.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1rc1 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.15 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.7 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module
Use this patch https://github.com/Olivine-Labs/busted/pull/631 resolves my problem.
I use
resty
to run unit tests against an openresty project, but any files whichrequire
this shell module will fail with this message:The fact that this is a test doesn't matter, even a simple
require
will crash the script. The trace points to this line: