Openresty is based on lua-jit but it is hard to find a proper unit-test tool when we need to test the lua module. So this repo use docker to build an environment to test lua scripts easily. We use busted as the base unit-test framework, and the it can use api post to test the lua scripts as usual.
To pull docker needed
bash pull.sh
.
├── README.md
├── build.sh
├── default.conf
├── dockerbuild
│ └── base
│ ├── Dockerfile.openresty-base
│ ├── Dockerfile.openresty-unit-test
│ └── luarocks-3.9.1.tar.gz
├── log
│ ├── access.log
│ └── error.log
├── pull.sh
├── reload.sh
├── restart.sh
├── scripts
│ ├── af_common.lua
│ └── helloworld.lua
├── spec
│ └── helloworld_spec.lua
├── start.sh
├── stop.sh
├── stop_unittest.sh
├── unittest.sh
└── utilities
└── auto-test.sh
【busted】
sh unittest.sh
screen log busted-unit test result
sudo apt install luarocks
luarocks install busted
luarocks install luacov
You should install the dependency package yourself.
All the unit-test scripts should be in spec dir, end with *_spec.lua. If you want to change configuration path, change it in .busted.
busted
bash start.sh
bash stop.sh
bash restart.sh
bash reload.sh
Refer to the official documentation and install the lua environment on IDEs such as pycharm. https://github.com/luarocks/luarocks/wiki/Installation-instructions-for-Unix