Guide APISIX Development environment setup and run tests. Trigger when user mentions ”APISIX test”, ”run APISIX tests”, ”APISIX testing”, ”setup APISIX test environment”, ”TEST::NGINX”, ”prove test”, ”APISIX CI”, ”test-nginx”, ”APISIX development environment”, ”APISIX deployment mode”, ”config_provi
npx playbooks add skill skyeyoung/apisix-skills --skill apisix-dev
This skill guides you through setting up the APISIX testing environment and running tests using TEST::NGINX.
IMPORTANT: Direct test execution is only supported on Ubuntu.
Before proceeding, check the operating system:
uname -a && cat /etc/os-release 2>/dev/null | head -5
If NOT Ubuntu:
git clone https://github.com/apache/apisix.git
cd apisix
code .
# In VSCode: Cmd/Ctrl+Shift+P -> "Dev Containers: Reopen in Container"
If Ubuntu: Proceed with the setup below.
git clone --recurse-submodules https://github.com/apache/apisix.git
cd apisix
If already cloned without submodules:
git submodule update --init --recursive
APISIX provides CI scripts that handle all dependency installation. Use these scripts to ensure consistency with the official CI environment.
Reference the CI workflow: https://github.com/apache/apisix/blob/master/.github/workflows/build.yml
Key CI Scripts:
ci/common.sh - Common utilities and dependency functionsci/linux_openresty_runner.sh - Main runner scriptci/linux_openresty_common_runner.sh - Installation functions (before_install, do_install)Run the installation:
# Source the CI scripts and run installation
cd apisix
# Set required environment variables
export OPENRESTY_VERSION=default
export SERVER_NAME=linux_openresty
# Source and run the CI installation functions
. ./ci/common.sh
. ./ci/linux_openresty_common_runner.sh
# Run before_install (installs system dependencies, Test::Nginx)
before_install
# Run do_install (installs OpenResty, Lua deps, test-nginx, etc.)
do_install
What the CI scripts install:
make deps)Note: etcd runs in Docker container, not installed locally.
# Verify OpenResty
openresty -v
# Verify test-nginx exists
ls test-nginx/
Note: If you encounter issues with the CI scripts, check the latest build.yml for any changes to the installation process. The CI scripts are the source of truth for the test environment setup.
Set these environment variables before running tests:
export OPENRESTY_PREFIX="/usr/local/openresty"
export PATH=$OPENRESTY_PREFIX/nginx/sbin:$OPENRESTY_PREFIX/luajit/bin:$OPENRESTY_PREFIX/bin:$PATH
# Optional - adjust based on your setup
export OPENRESTY_VERSION=default
export SERVER_NAME=linux_openresty
Verify the setup:
which openresty
openresty -v
which etcd
etcd --version
Tests use the prove command with TEST::NGINX. Run from the APISIX repository root:
# Run a single test file
FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ t/path/to/test.t
# Example: Run a specific test
FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ t/plugin/limit-count.t
| Option | Description |
| -------------------- | --------------------------------------------- |
| FLUSH_ETCD=1 | Flush etcd before running tests (recommended) |
| -I./test-nginx/lib | Include test-nginx library path |
| -I./ | Include current directory |
| -v | Verbose output |
| -r | Recurse into directories |
# Run all tests in a directory
FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ -r t/plugin/
# Run tests matching a pattern
FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ t/plugin/limit-*.t
Before running tests, start the CI environment using Docker:
# Start all required services (etcd, etc.) via Docker
make ci-env-up project_compose_ci=ci/pod/docker-compose.common.yml
This starts the necessary containers including etcd. No manual etcd installation is required.
To stop the services:
make ci-env-down
IMPORTANT: Always lint test files before committing.
# Lint all code (source + tests)
make lint
# Or run individual lint scripts
./utils/check-lua-code-style.sh # Lint source code
./utils/check-test-code-style.sh # Lint test files
The make lint target:
utils target (downloads linting utilities)check-lua-code-style.sh for source codecheck-test-code-style.sh for test filesReference: https://github.com/apache/apisix/blob/master/Makefile#L171-L178
For initial testing, you can skip these steps from the CI workflow:
Reference: https://apisix.apache.org/docs/apisix/deployment-modes/
APISIX supports three deployment modes:
| Mode | Description | Config Provider |
| ------------- | ----------------------------------- | --------------- |
| traditional | Data plane + control plane together | etcd only |
| decoupled | Separate data/control planes | etcd only |
| standalone | Data plane with local file config | yaml or json |
CRITICAL: Only data_plane role supports config_provider: yaml.
CORRECT configuration (in conf/config.yaml):
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
INCORRECT - This does NOT work:
# DO NOT USE - traditional role does not support yaml config provider
deployment:
role: traditional
role_traditional:
config_provider: yaml
Symptoms of incorrect configuration:
config.yaml gets overwritten when running apisix start/reload/initapisix.yaml has no effectWhen using config_provider: yaml:
conf/apisix.yaml#END marker for APISIX to load itExample conf/apisix.yaml:
routes:
- uri: /hello
upstream:
nodes:
'127.0.0.1:8080': 1
type: roundrobin
#END
IMPORTANT: Always check the official CI workflow for the latest installation process. The CI scripts are maintained by the APISIX team and are the source of truth.
Official CI workflow: https://github.com/apache/apisix/blob/master/.github/workflows/build.yml
Key CI scripts in the repository:
| Script | Purpose |
| ------------------------------------- | --------------------------------------------------------- |
| ci/common.sh | Common utilities, dependency functions, tool installation |
| ci/linux_openresty_runner.sh | Main Linux runner (sources common_runner) |
| ci/linux_openresty_common_runner.sh | before_install(), do_install(), script() functions |
CI Functions:
before_install() - Installs system dependencies, Test::Nginxdo_install() - Installs OpenResty, etcd, Lua deps, test-nginx, grpcurl, etc.script() - Runs the actual test suiteWhen something doesn't work: Check if the CI scripts have been updated. The build.yml and CI scripts evolve with the project.
Ensure OpenResty is in PATH:
export PATH=/usr/local/openresty/nginx/sbin:$PATH
which nginx
Ensure the CI environment is running:
# Start CI services (includes etcd)
make ci-env-up project_compose_ci=ci/pod/docker-compose.common.yml
# Check if containers are running
docker ps | grep etcd
Some tests require sudo:
sudo -E FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ t/path/to/test.t
Reinstall dependencies:
make deps
Re-initialize submodules:
git submodule update --init --recursive
APISIX tests are written using TEST::NGINX, a Perl-based testing framework.
IMPORTANT: When writing new tests, always reference similar existing tests in the APISIX repository first.
Test directory: https://github.com/apache/apisix/tree/master/t
| Directory | Test Type |
|-----------|-----------|
| t/plugin/ | Plugin tests (limit-count, key-auth, cors, etc.) |
| t/admin/ | Admin API tests |
| t/core/ | Core functionality tests |
| t/node/ | Node/upstream tests |
| t/router/ | Router tests |
| t/stream/ | Stream proxy tests |
| t/discovery/ | Service discovery tests |
| t/xrpc/ | xRPC protocol tests |
How to find similar tests:
# Search for tests related to a plugin
ls t/plugin/ | grep -i <keyword>
# Search for specific patterns in test files
grep -r "your_pattern" t/
# Example: Find tests using key-auth
grep -r "key-auth" t/plugin/
Why reference existing tests:
use t::APISIX 'no_plan';
repeat_each(1);
no_long_string();
no_root_location();
run_tests;
__DATA__
=== TEST 1: test description
--- config
location /t {
content_by_lua_block {
-- test code here
}
}
--- request
GET /t
--- response_body
expected response
--- no_error_log
[error]
| Section | Description |
| ------------------- | -------------------------------------------- |
| --- config | Nginx configuration |
| --- request | HTTP request to send |
| --- response_body | Expected response body |
| --- error_code | Expected HTTP status code |
| --- no_error_log | Patterns that should NOT appear in error log |
| --- error_log | Patterns that SHOULD appear in error log |
If you're not on Ubuntu:
Example error sharing format:
Command: FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ t/plugin/limit-count.t
Error:
[paste complete error output here]Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.