NAME

Test::Nginx::Socket - Socket-backed test scaffold for the Nginx C modules

SYNOPSIS

use Test::Nginx::Socket;

plan tests => $Test::Nginx::Socket::RepeatEach * 2 * blocks();

run_tests();

__DATA__

=== TEST 1: sanity
--- config
    location /echo {
        echo_before_body hello;
        echo world;
    }
--- request
    GET /echo
--- response_body
hello
world
--- error_code: 200


=== TEST 2: set Server
--- config
    location /foo {
        echo hi;
        more_set_headers 'Server: Foo';
    }
--- request
    GET /foo
--- response_headers
Server: Foo
--- response_body
hi


=== TEST 3: clear Server
--- config
    location /foo {
        echo hi;
        more_clear_headers 'Server: ';
    }
--- request
    GET /foo
--- response_headers_like
Server: nginx.*
--- response_body
hi


=== TEST 3: chunk size too small
--- config
    chunkin on;
    location /main {
        echo_request_body;
    }
--- more_headers
Transfer-Encoding: chunked
--- request eval
"POST /main
4\r
hello\r
0\r
\r
"
--- error_code: 400
--- response_body_like: 400 Bad Request

DESCRIPTION

This module provides a test scaffold based on non-blocking IO::Socket for automated testing in Nginx C module development.

This class inherits from Test::Base, thus bringing all its declarative power to the Nginx C module testing practices.

You need to terminate or kill any Nginx processes before running the test suite if you have changed the Nginx server binary. Normally it's as simple as

killall nginx
PATH=/path/to/your/nginx-with-memc-module:$PATH prove -r t

This module will create a temporary server root under t/servroot/ of the current working directory and starts and uses the nginx executable in the PATH environment.

You will often want to look into t/servroot/logs/error.log when things go wrong ;)

Sections supported

The following sections are supported:

config
http_config
request
request_eval
more_headers
response_body
response_body_eval
response_body_like
response_headers
response_headers_like
error_code
raw_request
user_files
skip_nginx
skip_nginx2

Both string scalar and string arrays are supported as values.

raw_request_middle_delay

Delay in sec between sending successive packets in the "raw_request" array value.

Samples

You'll find live samples in the following Nginx 3rd-party modules:

ngx_echo

http://github.com/agentzh/echo-nginx-module

ngx_chunkin

http://wiki.nginx.org/NginxHttpChunkinModule

ngx_memc

http://wiki.nginx.org/NginxHttpMemcModule

ngx_drizzle

http://github.com/chaoslawful/drizzle-nginx-module

ngx_rds_json

http://github.com/agentzh/rds-json-nginx-module

ngx_xss

http://github.com/agentzh/xss-nginx-module

ngx_srcache

http://github.com/agentzh/srcache-nginx-module

ngx_lua

http://github.com/chaoslawful/lua-nginx-module

ngx_set_misc

http://github.com/agentzh/set-misc-nginx-module

ngx_array_var

http://github.com/agentzh/array-var-nginx-module

ngx_form_input

http://github.com/calio/form-input-nginx-module

ngx_iconv

http://github.com/calio/iconv-nginx-module

ngx_set_cconv

http://github.com/liseen/set-cconv-nginx-module

ngx_postgres

http://github.com/FRiCKLE/ngx_postgres

ngx_coolkit

http://github.com/FRiCKLE/ngx_coolkit

SOURCE REPOSITORY

This module has a Git repository on Github, which has access for all.

http://github.com/agentzh/test-nginx

If you want a commit bit, feel free to drop me a line.

AUTHOR

agentzh (章亦春) <agentzh@gmail.com>

COPYRIGHT & LICENSE

Copyright (c) 2009, Taobao Inc., Alibaba Group (http://www.taobao.com).

Copyright (c) 2009, agentzh <agentzh@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 Taobao Inc. 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.

SEE ALSO

Test::Nginx::LWP, Test::Base.