-
I'm trying to write and run some test for my custom plugins, but with no success. SetupHere's my setup:
Changes for Custom Plugin TestI have a super simple custom plugin called custom-test, located at local core = require("apisix.core")
local schema = {
type = "object",
properties = {
debug = {
description = "Enable logs",
type = "boolean",
default = false
},
},
}
local _M = {
version = 0.1,
priority = 5000,
name = "custom-test",
schema = schema,
}
function _M.check_schema(conf, schema_type)
return core.schema.check(schema, conf)
end
function _M.rewrite(conf, ctx)
if conf.debug then
core.log.warn("\n\ncustom-test\n\n")
end
core.response.exit(200, { message = "custom-test" })
end
return _M I have this config.yaml, located at apisix:
extra_lua_path: "/home/apisix/apisix_src/apisix/plugins/custom/?.lua"
node_listen: 1984
proxy_mode: "http&stream"
stream_proxy:
tcp:
- 9100
enable_resolv_search_opt: false
plugins:
# [...] Other plugins
- custom-test And I modified APISIX.pm (located at # $user_yaml_config = <<_EOC_;
# apisix:
# node_listen: 1984
# proxy_mode: http&stream
# stream_proxy:
# tcp:
# - 9100
# enable_resolv_search_opt: false
# _EOC_ TestTo test the correct loading of the custom plugin I use the following command, since in case of errors they fail due to the error entries in error.log: cd /home/apisix/apisix_src
FLUSH_ETCD=1 TEST_NGINX_BINARY="/usr/local/openresty/nginx/sbin/nginx" prove -I. -Itest-nginx/lib -r "/home/apisix/apisix_src/t/plugin/echo.t" ResultsWithout the changes to APISIX.pm (uncommented lines 97-105) the echo tests succeed:
With the changes I made to test the custom plugin I get these errors:
Which, appearently, suggest that APISIX is not searching the custom plugin by using the Does anybody know what am I doing wrong or how can I fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Just found out why: APISIX.pm line 258 this makes As a simple workaround, I just moved the extra path from config.yaml file to the end of lua_package_path "$apisix_home/?.lua;$apisix_home/?/init.lua;$apisix_home/deps/share/lua/5.1/?/init.lua;$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/apisix/?.lua;$apisix_home/t/?.lua;$apisix_home/t/xrpc/?.lua;$apisix_home/t/xrpc/?/init.lua;/home/apisix/apisix_src/apisix/plugins/custom/?.lua;;"; |
Beta Was this translation helpful? Give feedback.
Just found out why: APISIX.pm line 258
this makes
extra_lua_path
parameter in config.yaml useless 👀As a simple workaround, I just moved the extra path from config.yaml file to the end of
lua_package_path
variable:lua_package_path "$apisix_home/?.lua;$apisix_home/?/init.lua;$apisix_home/deps/share/lua/5.1/?/init.lua;$apisix_home/deps/share/lua/5.1/?.lua;$apisix_home/apisix/?.lua;$apisix_home/t/?.lua;$apisix_home/t/xrpc/?.lua;$apisix_home/t/xrpc/?/init.lua;/home/apisix/apisix_src/apisix/plugins/custom/?.lua;;";