fix: support extra_lua_path in test framework
Description
This PR adds support for setting custom Lua paths (extra_lua_path and extra_lua_cpath) in test files, aligning the test framework behavior with APISIX runtime configuration.
Previously, while APISIX runtime supported apisix.extra_lua_path in config.yaml to load custom plugins from specified directories, the test framework (t/APISIX.pm) did not respect this configuration. This made it impossible to write tests for custom plugins located in custom directories.
This PR implements two complementary methods for setting custom Lua paths in tests:
Method 1: Block definitions (preferred) --- extra_lua_path: /custom/path/?.lua --- extra_lua_cpath: /custom/path/?.soMethod 2: Automatic parsing from extra_yaml_config --- extra_yaml_config apisix: extra_lua_path: "/custom/path/?.lua" extra_lua_cpath: "/custom/path/?.so"The implementation:
- Prepends custom paths to
lua_package_pathandlua_package_cpath(matching runtime behavior) - Block definitions take precedence when both methods are used
- Enables testing custom plugins without modifying core APISIX paths
Which issue(s) this PR fixes:
Fixes #12389
Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)
Test Coverage:
Added comprehensive test suite in t/admin/extra-lua-path.t covering:
- Path addition via block definitions
- YAML configuration parsing
- Simultaneous lua_path and lua_cpath configuration
- Correct path prepending behavior
- Precedence rules between configuration methods
Backward Compatibility:
This change is fully backward compatible. It only adds new optional block definitions (extra_lua_path, extra_lua_cpath) and parsing logic for existing extra_yaml_config. All existing tests continue to work without modification.
Hi @grapestore, you can merge the latest main branch to make CI pass.
I’ve updated my branch to follow the latest master branch
Could you please take a look?
@membphis
Here is a real scenario:
We use the official APISIX Docker image while developing custom plugins. The custom plugin directory is mounted into the container, and in tests we add that directory to extra_lua_path so the plugin can be loaded.
Example:
Mount local custom plugins to /usr/local/apisix/custom/plugins In the test: apisix.extra_lua_path: "/usr/local/apisix/custom/plugins/?.lua" The issue is that the test framework does not prepend this extra_lua_path to lua_package_path. As a result, during tests the custom plugin path is not included in package.path, and require fails to load the plugin. This works correctly in a real APISIX runtime, but the test environment cannot see the plugin, causing inconsistent behavior.
This scenario clearly shows the problem where extra_lua_path is not applied in the test framework.
I mean:
you should add a test case to cove the case you show me right now