0

I'd like to find a way to make unit testing on my custom nginx modules but failed. Could anyone provide some suggestions? I once found the Test::Nginx framework, but it works as system test. Some people told me that I can use ngx_lua_module to expose C function in nginx module by the way of FFI. Could anyone know how to do that?

1 Answers1

0

You can compile that custom module as a library and then load the function with FFI with any available language that supports it e.g. Python with Ctypes or directly in C by linking against that new library and then using its symbols (such as functions) to assert against certain behavior / return values.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • Thanks for your answer, while, the function or C struct in nginx module may need nginx environment, I don't know how to make sure its successful running without nginx. – Lei Liu Jul 14 '21 at 09:11
  • @LeiLiu If you at least `#include` any nginx-related module or any other external module and use it, it'll for sure be required and will not work as a standalone code. Link against the libraries you use and then it'll work depending on the link type i.e. if dynamically it'll look for e.g. nginx's `.so` files and if statically, it'll work fine alone. – Peter Badida Jul 14 '21 at 09:17