Test::Nginx(3pm)
β¨ Test::Nginx β¨
okay bestie, welcome to Test::Nginx (that's the Test::Nginx(3pm) page you just opened, hi π) β a data-driven test scaffold for Nginx C module and Nginx/OpenResty-based libraries and applications. yes she does it all. π
πΈ DESCRIPTION πΈ
so this distribution? it hands you two testing modules for Nginx C module development:
Test::Nginx::Socketβ bestie this is the highly recommended one, periodt. π- and guess what, this library also has the following subclasses:
Test::Nginx::Socket::LuaTest::Nginx::Socket::Lua::StreamTest::Nginx::Socket::Lua::Dgram
- and guess what, this library also has the following subclasses:
Test::Nginx::LWPβ this one is obsolete. it's giving throwback, ngl. π
all of them are based on Test::Base, so they're all cousins fr fr.
usually, Test::Nginx::Socket is the preference because it works on a much lower level and is not that fault tolerant like Test::Nginx::LWP. lowkey the whole point.
also β and this is the tea β β a lot of connection hang issues (like a wrong r->main->count value in nginx 0.8.x) can only be captured by Test::Nginx::Socket, because Perl's LWP::UserAgent client will close the connection itself, and that will conceal such issues from the testers. so like, LWP is literally hiding the crime. π
Test::Nginx automatically starts an nginx instance (from the PATH env) rooted at t/servroot/, and the default config template makes this nginx instance listen on the port 1984 by default. iconic number honestly.
you can specify a different port number by setting his port number to the TEST_NGINX_PORT environment, as in:
export TEST_NGINX_PORT=1989
slay. that's it, that's the whole thing. β¨
π User Guide π
you can find a comprehensive user guide on this test framework in my upcoming book "Programming OpenResty":
https://openresty.gitbooks.io/programming-openresty/content/testing/index.html
go read it bestie, it's giving educational. π¦
π₯ Nginx C modules that use Test::Nginx to drive their test suites π₯
ngx_echoβhttps://github.com/openresty/echo-nginx-modulengx_headers_moreβhttps://github.com/openresty/headers-more-nginx-modulengx_chunkinβhttp://wiki.nginx.org/NginxHttpChunkinModulengx_memcβhttp://wiki.nginx.org/NginxHttpMemcModulengx_drizzleβhttps://github.com/openresty/drizzle-nginx-modulengx_rds_jsonβhttps://github.com/openresty/rds-json-nginx-modulengx_rds_csvβhttps://github.com/openresty/rds-csv-nginx-modulengx_xssβhttps://github.com/openresty/xss-nginx-modulengx_srcacheβhttps://github.com/openresty/srcache-nginx-modulengx_luaβhttps://github.com/openresty/lua-nginx-modulengx_set_miscβhttps://github.com/openresty/set-misc-nginx-modulengx_array_varβhttps://github.com/openresty/array-var-nginx-modulengx_form_inputβhttps://github.com/calio/form-input-nginx-modulengx_iconvβhttps://github.com/calio/iconv-nginx-modulengx_set_cconvβhttps://github.com/liseen/set-cconv-nginx-modulengx_postgresβhttps://github.com/FRiCKLE/ngx_postgresngx_coolkitβhttps://github.com/FRiCKLE/ngx_coolkitNaxsiβhttps://github.com/nbs-system/naxsingx_shibbolethβhttps://github.com/nginx-shib/nginx-http-shibboleth
look at that roster. main character energy across the board. π
π INSTALLATION π
if you have cpan installed, you can simply run the command to install this module:
sudo cpan Test::Nginx
if you want to install from the source code directory directly, you can run:
sudo cpan .
if you prefer cpanm to cpan (like I do!), you can replace cpan in the commands above with cpanm. we love a one-word swap. π«Ά
otherwise you can install this module in the good old way below:
perl Makefile.PL
make
sudo make install
old school, still valid, still eating. π
π SOURCE REPOSITORY π
this module has a Git repository on Github, which has access for all.
https://github.com/openresty/test-nginx
if you want a commit bit, feel free to drop me a line. not me casually offering you the keys to the kingdom. π
π DEBIAN PACKAGES π
AntΓ³nio P. P. Almeida is maintaining a Debian package for this module in his Debian repository:
shoutout AntΓ³nio, doing the lord's work. π
π§ Community π§
English Mailing List
the openresty-en mailing list is for English speakers:
https://groups.google.com/group/openresty-en
Chinese Mailing List
the openresty mailing list is for Chinese speakers:
https://groups.google.com/group/openresty
both vibes, both valid, join whichever speaks your language bestie. π
β AUTHORS β
- Yichun Zhang (agentzh)
"<agentzh@gmail.com>", OpenResty Inc. - Antoine BONAVITA
"<antoine.bonavita@gmail.com>"
two icons. two legends. π«‘
π COPYRIGHT & LICENSE π
Copyright (c) 2009-2025, Yichun Zhang (agentzh) "<agentzh@gmail.com>", OpenResty Inc.
Copyright (c) 2011-2012, Antoine Bonavita "<antoine.bonavita@gmail.com>".
this module is licensed under the terms of the BSD license.
redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the authors nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(that's the all-caps legal bit, bestie β dramatic on purpose, don't fear it, just respect it. βπ)
πΈ SEE ALSO πΈ
Test::Nginx::LWP, Test::Nginx::Socket, Test::Base.
go forth and test, my love. β¨
and that's a wrap, bestie! π this page is perl v5.40.1 coded, dated 2026-08-10, and it's Test::Nginx(3pm) β the user-contributed Perl documentation, one of one, no notes. stay hydrated, keep your ports open, and go write some slay tests. π¦π
π
π¦ where this page comes from
- ubuntu stonking: libtest-nginx-perl 0.32.9.g58cf0d5-4 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms