Mercurial > hg > nginx-tests
comparison lib/Test/Nginx.pm @ 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 | 4bf7a819358c |
comparison
equal
deleted
inserted
replaced
106:7a712d3909ba | 107:1c0ec30614c6 |
---|---|
49 if ($ENV{TEST_NGINX_CATLOG}) { | 49 if ($ENV{TEST_NGINX_CATLOG}) { |
50 system("cat $self->{_testdir}/error.log"); | 50 system("cat $self->{_testdir}/error.log"); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 sub has { | 54 sub has($) { |
55 my ($self, $feature) = @_; | |
56 | |
57 Test::More::plan(skip_all => "$feature not compiled in") | |
58 unless $self->has_module($feature); | |
59 | |
60 return $self; | |
61 } | |
62 | |
63 sub has_module($) { | |
55 my ($self, $feature) = @_; | 64 my ($self, $feature) = @_; |
56 | 65 |
57 my %regex = ( | 66 my %regex = ( |
58 mail => '--with-mail', | 67 mail => '--with-mail', |
59 flv => '--with-http_flv_module', | 68 flv => '--with-http_flv_module', |
60 rewrite => '(?s)^(?!.*--without-http_rewrite_module)', | 69 rewrite => '(?s)^(?!.*--without-http_rewrite_module)', |
61 gzip => '(?s)^(?!.*--without-http_gzip_module)', | 70 gzip => '(?s)^(?!.*--without-http_gzip_module)', |
62 cache => '(?s)^(?!.*--without-http-cache)', | 71 cache => '(?s)^(?!.*--without-http-cache)', |
72 fastcgi => '(?s)^(?!.*--without-http_fastcgi_module)', | |
73 proxy => '(?s)^(?!.*--without-http_proxy_module)', | |
63 ); | 74 ); |
64 | 75 |
65 my $re = $regex{$feature}; | 76 my $re = $regex{$feature}; |
66 $re = $feature if !defined $re; | 77 $re = $feature if !defined $re; |
67 | 78 |
68 Test::More::plan(skip_all => "$feature not compiled in") | 79 $self->{_configure_args} = `$NGINX -V 2>&1` |
69 unless `$NGINX -V 2>&1` =~ $re; | 80 if !defined $self->{_configure_args}; |
70 | 81 |
71 return $self; | 82 return ($self->{_configure_args} =~ $re) ? 1 : 0; |
72 } | 83 } |
73 | 84 |
74 sub has_daemon($) { | 85 sub has_daemon($) { |
75 my ($self, $daemon) = @_; | 86 my ($self, $daemon) = @_; |
76 | 87 |
100 | 111 |
101 my $pid = fork(); | 112 my $pid = fork(); |
102 die "Unable to fork(): $!\n" unless defined $pid; | 113 die "Unable to fork(): $!\n" unless defined $pid; |
103 | 114 |
104 if ($pid == 0) { | 115 if ($pid == 0) { |
105 exec($NGINX, '-c', "$testdir/nginx.conf", '-g', | 116 my @globals = $self->{_test_globals} ? |
106 "pid $testdir/nginx.pid; " | 117 () : ('-g', "pid $testdir/nginx.pid; " |
107 . "error_log $testdir/error.log debug;") | 118 . "error_log $testdir/error.log debug;"); |
119 exec($NGINX, '-c', "$testdir/nginx.conf", @globals) | |
108 or die "Unable to exec(): $!\n"; | 120 or die "Unable to exec(): $!\n"; |
109 } | 121 } |
110 | 122 |
111 # wait for nginx to start | 123 # wait for nginx to start |
112 | 124 |
180 } | 192 } |
181 | 193 |
182 sub write_file_expand($$) { | 194 sub write_file_expand($$) { |
183 my ($self, $name, $content) = @_; | 195 my ($self, $name, $content) = @_; |
184 | 196 |
197 $content =~ s/%%TEST_GLOBALS%%/$self->test_globals()/gmse; | |
198 $content =~ s/%%TEST_GLOBALS_HTTP%%/$self->test_globals_http()/gmse; | |
185 $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms; | 199 $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms; |
186 | 200 |
187 return $self->write_file($name, $content); | 201 return $self->write_file($name, $content); |
188 } | 202 } |
189 | 203 |
209 } | 223 } |
210 | 224 |
211 sub testdir() { | 225 sub testdir() { |
212 my ($self) = @_; | 226 my ($self) = @_; |
213 return $self->{_testdir}; | 227 return $self->{_testdir}; |
228 } | |
229 | |
230 sub test_globals() { | |
231 my ($self) = @_; | |
232 | |
233 return $self->{_test_globals} | |
234 if defined $self->{_test_globals}; | |
235 | |
236 my $s = ''; | |
237 | |
238 $s .= "pid $self->{_testdir}/nginx.pid;\n"; | |
239 $s .= "error_log $self->{_testdir}/error.log debug;\n"; | |
240 | |
241 $self->{_test_globals} = $s; | |
242 } | |
243 | |
244 sub test_globals_http() { | |
245 my ($self) = @_; | |
246 | |
247 return $self->{_test_globals_http} | |
248 if defined $self->{_test_globals_http}; | |
249 | |
250 my $s = ''; | |
251 | |
252 $s .= "root $self->{_testdir};\n"; | |
253 $s .= "access_log $self->{_testdir}/access.log;\n"; | |
254 $s .= "client_body_temp_path $self->{_testdir}/client_body_temp;\n"; | |
255 | |
256 $s .= "fastcgi_temp_path $self->{_testdir}/fastcgi_temp;\n" | |
257 if $self->has_module('fastcgi'); | |
258 | |
259 $s .= "proxy_temp_path $self->{_testdir}/proxy_temp;\n" | |
260 if $self->has_module('proxy'); | |
261 | |
262 $self->{_test_globals_http} = $s; | |
214 } | 263 } |
215 | 264 |
216 ############################################################################### | 265 ############################################################################### |
217 | 266 |
218 sub log_core { | 267 sub log_core { |