test: 基于 nginx-module-lua 的 Lua 测试框架
安装
如果您尚未设置 RPM 仓库订阅,请 注册。然后您可以继续以下步骤。
CentOS/RHEL 7 或 Amazon Linux 2
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install lua-resty-test
CentOS/RHEL 8+、Fedora Linux、Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install lua5.1-resty-test
要在 NGINX 中使用此 Lua 库,请确保已安装 nginx-module-lua。
本文档描述了 lua-resty-test v0.1,于 2019 年 9 月 03 日发布。
此 Lua 库是用于测试您的 ngx_lua 源代码或其他服务器(tcp 或 udp)的测试框架:
http://wiki.nginx.org/HttpLuaModule
概述
-- test.lua
local iresty_test = require "resty.iresty_test"
local tb = iresty_test.new({unit_name="example"})
function tb:init( )
self:log("init complete")
end
function tb:test_00001( )
error("invalid input")
end
function tb:atest_00002()
self:log("never be called")
end
function tb:test_00003( )
self:log("ok")
end
-- 单元测试
tb:run()
运行测试用例:

另见
- ngx_lua 模块: http://wiki.nginx.org/HttpLuaModule
GitHub
您可以在 nginx-module-test 的 GitHub 仓库 中找到此模块的其他配置技巧和文档。