Mercurial > hg > nginx-tests
changeset 107:1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
TEST_GLOBALS replaces previously used -g switch. This allows tests
to be executed on 0.6.* branch. For compatibility with old tests -g switch
will be used if TEST_GLOBALS wasn't expaneded in config.
TEST_GLOBALS_HTTP replaces multiple variables (access_log, root,
client_body_temp_path, proxy_temp_path, fastcgi_temp_path) previously
specified directly in test configs. This change reduce duplication and
allows tests to be used with nginx compiled without fastcgi and/or proxy
modules (as proxy_temp_path and fastcgi_temp_path are added conditionally).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 14 Oct 2009 02:23:52 +0400 |
parents | 7a712d3909ba |
children | 93a8f4202b16 |
files | expect-100-continue.t fastcgi.t gzip.t imap.t lib/Test/Nginx.pm limit-req.t memcached.t pop3.t proxy-cache.t proxy-chunked.t proxy-noclose.t proxy-store.t proxy-xar.t proxy.t range-flv.t range.t rewrite.t smtp-greeting-delay.t smtp-xclient.t smtp.t ssi-include-big.t ssi.t |
diffstat | 22 files changed, 119 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/expect-100-continue.t Tue Oct 13 05:16:45 2009 +0400 +++ b/expect-100-continue.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/fastcgi.t Tue Oct 13 05:16:45 2009 +0400 +++ b/fastcgi.t Wed Oct 14 02:23:52 2009 +0400 @@ -24,9 +24,11 @@ eval { require FCGI; }; plan(skip_all => 'FCGI not installed') if $@; -my $t = Test::Nginx->new()->plan(4) +my $t = Test::Nginx->new()->has('fastcgi')->plan(4) ->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -34,11 +36,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/gzip.t Tue Oct 13 05:16:45 2009 +0400 +++ b/gzip.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/imap.t Tue Oct 13 05:16:45 2009 +0400 +++ b/imap.t Wed Oct 14 02:23:52 2009 +0400 @@ -33,6 +33,8 @@ ->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon) ->write_file_expand('nginx.conf', <<'EOF')->run(); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -50,11 +52,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/lib/Test/Nginx.pm Tue Oct 13 05:16:45 2009 +0400 +++ b/lib/Test/Nginx.pm Wed Oct 14 02:23:52 2009 +0400 @@ -51,7 +51,16 @@ } } -sub has { +sub has($) { + my ($self, $feature) = @_; + + Test::More::plan(skip_all => "$feature not compiled in") + unless $self->has_module($feature); + + return $self; +} + +sub has_module($) { my ($self, $feature) = @_; my %regex = ( @@ -60,15 +69,17 @@ rewrite => '(?s)^(?!.*--without-http_rewrite_module)', gzip => '(?s)^(?!.*--without-http_gzip_module)', cache => '(?s)^(?!.*--without-http-cache)', + fastcgi => '(?s)^(?!.*--without-http_fastcgi_module)', + proxy => '(?s)^(?!.*--without-http_proxy_module)', ); my $re = $regex{$feature}; $re = $feature if !defined $re; - Test::More::plan(skip_all => "$feature not compiled in") - unless `$NGINX -V 2>&1` =~ $re; + $self->{_configure_args} = `$NGINX -V 2>&1` + if !defined $self->{_configure_args}; - return $self; + return ($self->{_configure_args} =~ $re) ? 1 : 0; } sub has_daemon($) { @@ -102,9 +113,10 @@ die "Unable to fork(): $!\n" unless defined $pid; if ($pid == 0) { - exec($NGINX, '-c', "$testdir/nginx.conf", '-g', - "pid $testdir/nginx.pid; " - . "error_log $testdir/error.log debug;") + my @globals = $self->{_test_globals} ? + () : ('-g', "pid $testdir/nginx.pid; " + . "error_log $testdir/error.log debug;"); + exec($NGINX, '-c', "$testdir/nginx.conf", @globals) or die "Unable to exec(): $!\n"; } @@ -182,6 +194,8 @@ sub write_file_expand($$) { my ($self, $name, $content) = @_; + $content =~ s/%%TEST_GLOBALS%%/$self->test_globals()/gmse; + $content =~ s/%%TEST_GLOBALS_HTTP%%/$self->test_globals_http()/gmse; $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms; return $self->write_file($name, $content); @@ -213,6 +227,41 @@ return $self->{_testdir}; } +sub test_globals() { + my ($self) = @_; + + return $self->{_test_globals} + if defined $self->{_test_globals}; + + my $s = ''; + + $s .= "pid $self->{_testdir}/nginx.pid;\n"; + $s .= "error_log $self->{_testdir}/error.log debug;\n"; + + $self->{_test_globals} = $s; +} + +sub test_globals_http() { + my ($self) = @_; + + return $self->{_test_globals_http} + if defined $self->{_test_globals_http}; + + my $s = ''; + + $s .= "root $self->{_testdir};\n"; + $s .= "access_log $self->{_testdir}/access.log;\n"; + $s .= "client_body_temp_path $self->{_testdir}/client_body_temp;\n"; + + $s .= "fastcgi_temp_path $self->{_testdir}/fastcgi_temp;\n" + if $self->has_module('fastcgi'); + + $s .= "proxy_temp_path $self->{_testdir}/proxy_temp;\n" + if $self->has_module('proxy'); + + $self->{_test_globals_http} = $s; +} + ############################################################################### sub log_core {
--- a/limit-req.t Tue Oct 13 05:16:45 2009 +0400 +++ b/limit-req.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; limit_req_zone $binary_remote_addr zone=long:10m rate=1r/m;
--- a/memcached.t Tue Oct 13 05:16:45 2009 +0400 +++ b/memcached.t Wed Oct 14 02:23:52 2009 +0400 @@ -27,6 +27,8 @@ my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(4) ->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -34,11 +36,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/pop3.t Tue Oct 13 05:16:45 2009 +0400 +++ b/pop3.t Wed Oct 14 02:23:52 2009 +0400 @@ -33,6 +33,8 @@ ->run_daemon(\&Test::Nginx::POP3::pop3_test_daemon) ->write_file_expand('nginx.conf', <<'EOF')->run(); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -50,11 +52,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/proxy-cache.t Tue Oct 13 05:16:45 2009 +0400 +++ b/proxy-cache.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% proxy_cache_path %%TESTDIR%%/cache levels=1:2 keys_zone=NAME:10m;
--- a/proxy-chunked.t Tue Oct 13 05:16:45 2009 +0400 +++ b/proxy-chunked.t Wed Oct 14 02:23:52 2009 +0400 @@ -31,6 +31,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -38,12 +40,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/proxy-noclose.t Tue Oct 13 05:16:45 2009 +0400 +++ b/proxy-noclose.t Wed Oct 14 02:23:52 2009 +0400 @@ -36,6 +36,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -43,12 +45,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/proxy-store.t Tue Oct 13 05:16:45 2009 +0400 +++ b/proxy-store.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/proxy-xar.t Tue Oct 13 05:16:45 2009 +0400 +++ b/proxy-xar.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/proxy.t Tue Oct 13 05:16:45 2009 +0400 +++ b/proxy.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/range-flv.t Tue Oct 13 05:16:45 2009 +0400 +++ b/range-flv.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/range.t Tue Oct 13 05:16:45 2009 +0400 +++ b/range.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% charset_map B A { 58 59; # X -> Y
--- a/rewrite.t Tue Oct 13 05:16:45 2009 +0400 +++ b/rewrite.t Wed Oct 14 02:23:52 2009 +0400 @@ -24,6 +24,8 @@ my $t = Test::Nginx->new()->has('rewrite')->plan(5) ->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -31,11 +33,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/smtp-greeting-delay.t Tue Oct 13 05:16:45 2009 +0400 +++ b/smtp-greeting-delay.t Wed Oct 14 02:23:52 2009 +0400 @@ -23,6 +23,8 @@ my $t = Test::Nginx->new()->has('mail')->plan(2) ->write_file_expand('nginx.conf', <<'EOF')->run(); +%%TEST_GLOBALS%% + master_process off; daemon off;
--- a/smtp-xclient.t Tue Oct 13 05:16:45 2009 +0400 +++ b/smtp-xclient.t Wed Oct 14 02:23:52 2009 +0400 @@ -29,6 +29,8 @@ ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon) ->write_file_expand('nginx.conf', <<'EOF')->run(); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -48,11 +50,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/smtp.t Tue Oct 13 05:16:45 2009 +0400 +++ b/smtp.t Wed Oct 14 02:23:52 2009 +0400 @@ -32,6 +32,8 @@ ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon) ->write_file_expand('nginx.conf', <<'EOF')->run(); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -51,11 +53,7 @@ } http { - access_log off; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% server { listen 127.0.0.1:8080;
--- a/ssi-include-big.t Tue Oct 13 05:16:45 2009 +0400 +++ b/ssi-include-big.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% output_buffers 2 512; ssi on;
--- a/ssi.t Tue Oct 13 05:16:45 2009 +0400 +++ b/ssi.t Wed Oct 14 02:23:52 2009 +0400 @@ -25,6 +25,8 @@ $t->write_file_expand('nginx.conf', <<'EOF'); +%%TEST_GLOBALS%% + master_process off; daemon off; @@ -32,12 +34,7 @@ } http { - access_log off; - root %%TESTDIR%%; - - client_body_temp_path %%TESTDIR%%/client_body_temp; - fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; - proxy_temp_path %%TESTDIR%%/proxy_temp; + %%TEST_GLOBALS_HTTP%% proxy_cache_path %%TESTDIR%%/cache levels=1:2 keys_zone=NAME:10m;