fix: support extra_lua_path in test framework#12759
fix: support extra_lua_path in test framework#12759grapestore wants to merge 11 commits intoapache:masterfrom
Conversation
Baoyuantop
left a comment
There was a problem hiding this comment.
Codes LGTM, please fix the failed CI
|
Hi @grapestore, you can merge the latest main branch to make CI pass. |
2b64c82 to
9c80b2c
Compare
|
I’ve updated my branch to follow the latest master branch |
|
Could you please take a look? |
membphis
left a comment
There was a problem hiding this comment.
we need a real case to cover this case
|
Here is a real scenario: We use the official APISIX Docker image while developing custom plugins. Example: Mount local custom plugins to /usr/local/apisix/custom/plugins 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 |
|
Hi @grapestore, following up on the previous review comments. Please let us know if you have any updates. Thank you. |
|
I added it @Baoyuantop @membphis |
0518a14 to
10e81dd
Compare
|
update rebase |
|
Hi @grapestore, the newly added test execution failed. |
|
check plz |
There was a problem hiding this comment.
Pull request overview
This PR adds support for custom Lua paths in the APISIX test framework, addressing a gap where the test framework didn't respect extra_lua_path and extra_lua_cpath configurations that are available in APISIX runtime. This enables developers to write tests for custom plugins located in custom directories.
Changes:
- Extended the test framework preprocessor in
t/APISIX.pmto extract and prepend custom Lua paths from block definitions or YAML configuration - Added comprehensive test coverage in
t/admin/extra-lua-path.tto verify all configuration methods and edge cases - Created a test plugin
test-extra-pathto demonstrate real-world usage
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| t/APISIX.pm | Core implementation that extracts extra_lua_path and extra_lua_cpath from block definitions or extra_yaml_config and prepends them to lua_package_path and lua_package_cpath |
| t/admin/extra-lua-path.t | Comprehensive test suite covering block definitions, YAML config parsing, precedence rules, path prepending, and real plugin loading |
| t/plugin/custom-plugins/apisix/plugins/test-extra-path.lua | Simple test plugin that sets custom headers to verify custom plugin loading works correctly |
| docs/en/latest/internal/testing-framework.md | Documentation update explaining both configuration methods and precedence rules |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Method 1: Block definition (preferred) | ||
| if ($block->extra_lua_path) { | ||
| $extra_lua_path = $block->extra_lua_path . ";"; |
There was a problem hiding this comment.
The code unconditionally appends a semicolon to the extra_lua_path value. If a user provides a path that already ends with a semicolon (e.g., /custom/path/?.lua;), this will result in a double semicolon (/custom/path/?.lua;;). While this is not harmful in practice (double semicolons in Lua package paths just add the default path), it's inconsistent with the runtime behavior in apisix/cli/ops.lua which checks if the path already ends with a semicolon before appending one.
Consider checking if the path already ends with a semicolon before appending, similar to the runtime implementation. The same applies to extra_lua_cpath on line 282.
|
Hi @grapestore, following up on the previous review comments. Please let us know if you have any updates. Thank you. |
moonming
left a comment
There was a problem hiding this comment.
Hi @grapestore, thank you for adding extra_lua_path support to the test framework!
This improves the developer experience for plugin developers who need custom Lua paths in their tests.
Please:
- Rebase on the latest master
- Add a brief description of how to use this feature in the test framework (a comment in
t/APISIX.pmor the PR description)
Thank you!
3ed05ea to
7adf5bf
Compare
Add support for setting custom Lua paths in test files through
two complementary methods:
1. Block definitions (preferred):
--- extra_lua_path: /custom/path/?.lua
--- extra_lua_cpath: /custom/path/?.so
2. YAML configuration parsing:
--- extra_yaml_config
apisix:
extra_lua_path: "/custom/path/?.lua"
The implementation prepends custom paths to lua_package_path and
lua_package_cpath, aligning test behavior with APISIX runtime where
extra_lua_path allows loading custom plugins from specified directories.
Block definitions take precedence when both methods are used, ensuring
explicit test configuration overrides YAML settings.
Added comprehensive test suite (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 methods
This enables testing custom plugins in custom directories without
modifying core APISIX paths.
Fixes apache#12389
7adf5bf to
0a0fecb
Compare
Description
This PR adds support for setting custom Lua paths (
extra_lua_pathandextra_lua_cpath) in test files, aligning the test framework behavior with APISIX runtime configuration.Previously, while APISIX runtime supported
apisix.extra_lua_pathinconfig.yamlto 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:
lua_package_pathandlua_package_cpath(matching runtime behavior)Which issue(s) this PR fixes:
Fixes #12389
Checklist
Test Coverage:
Added comprehensive test suite in
t/admin/extra-lua-path.tcovering: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 existingextra_yaml_config. All existing tests continue to work without modification.