Mercurial > hg > nginx-tests
comparison syslog.t @ 445:62d1f96c5ff4
Tests: syslog "if=" tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 06 Aug 2014 13:31:55 +0400 |
parents | 82b15c81978e |
children | a64b4057189c |
comparison
equal
deleted
inserted
replaced
444:d9cfff372a30 | 445:62d1f96c5ff4 |
---|---|
24 | 24 |
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | 25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
26 | 26 |
27 my $t = Test::Nginx->new()->has(qw/http limit_req/); | 27 my $t = Test::Nginx->new()->has(qw/http limit_req/); |
28 | 28 |
29 plan(skip_all => 'no syslog') unless $t->has_version('1.7.1'); | 29 plan(skip_all => 'no syslog if') unless $t->has_version('1.7.5'); |
30 | 30 |
31 $t->plan(56)->write_file_expand('nginx.conf', <<'EOF'); | 31 $t->plan(58)->write_file_expand('nginx.conf', <<'EOF'); |
32 | 32 |
33 %%TEST_GLOBALS%% | 33 %%TEST_GLOBALS%% |
34 | 34 |
35 error_log syslog:server=127.0.0.1:8083 info; | 35 error_log syslog:server=127.0.0.1:8083 info; |
36 error_log %%TESTDIR%%/f_glob.log info; | 36 error_log %%TESTDIR%%/f_glob.log info; |
44 %%TEST_GLOBALS_HTTP%% | 44 %%TEST_GLOBALS_HTTP%% |
45 | 45 |
46 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/m; | 46 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/m; |
47 | 47 |
48 log_format empty ""; | 48 log_format empty ""; |
49 log_format logf "$status"; | 49 log_format logf "$uri:$status"; |
50 | 50 |
51 error_log syslog:server=127.0.0.1:8084 info; | 51 error_log syslog:server=127.0.0.1:8084 info; |
52 error_log %%TESTDIR%%/f_http.log info; | 52 error_log %%TESTDIR%%/f_http.log info; |
53 | 53 |
54 server { | 54 server { |
88 access_log syslog:server=127.0.0.1:8080; | 88 access_log syslog:server=127.0.0.1:8080; |
89 } | 89 } |
90 location /a_logf { | 90 location /a_logf { |
91 access_log syslog:server=127.0.0.1:8080 logf; | 91 access_log syslog:server=127.0.0.1:8080 logf; |
92 } | 92 } |
93 location /if { | |
94 access_log syslog:server=127.0.0.1:8085 logf if=$arg_logme; | |
95 } | |
93 | 96 |
94 location /debug { | 97 location /debug { |
95 limit_req zone=one; | 98 limit_req zone=one; |
96 error_log syslog:server=127.0.0.1:8080 debug; | 99 error_log syslog:server=127.0.0.1:8080 debug; |
97 } | 100 } |
132 | 135 |
133 EOF | 136 EOF |
134 | 137 |
135 $t->run_daemon(\&syslog_daemon, 8083, $t, 's_glob.log'); | 138 $t->run_daemon(\&syslog_daemon, 8083, $t, 's_glob.log'); |
136 $t->run_daemon(\&syslog_daemon, 8084, $t, 's_http.log'); | 139 $t->run_daemon(\&syslog_daemon, 8084, $t, 's_http.log'); |
140 $t->run_daemon(\&syslog_daemon, 8085, $t, 's_if.log'); | |
137 | 141 |
138 $t->waitforfile($t->testdir . '/s_glob.log'); | 142 $t->waitforfile($t->testdir . '/s_glob.log'); |
139 $t->waitforfile($t->testdir . '/s_http.log'); | 143 $t->waitforfile($t->testdir . '/s_http.log'); |
144 $t->waitforfile($t->testdir . '/s_if.log'); | |
140 | 145 |
141 $t->run(); | 146 $t->run(); |
142 | 147 |
143 ############################################################################### | 148 ############################################################################### |
144 | 149 |
155 | 160 |
156 | 161 |
157 like(get_syslog('/e'), | 162 like(get_syslog('/e'), |
158 qr/nginx: \d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} \[error\]/, | 163 qr/nginx: \d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} \[error\]/, |
159 'error_log format'); | 164 'error_log format'); |
160 like(get_syslog('/a_logf'), qr/nginx: 404$/, 'access_log log_format'); | 165 like(get_syslog('/a_logf'), qr/nginx: \/a_logf:404$/, 'access_log log_format'); |
161 | 166 |
162 my @lines = split /<\d+>/, get_syslog('/a2'); | 167 my @lines = split /<\d+>/, get_syslog('/a2'); |
163 is($lines[1], $lines[2], 'access_log many'); | 168 is($lines[1], $lines[2], 'access_log many'); |
164 | 169 |
165 @lines = split /<\d+>/, get_syslog('/e2'); | 170 @lines = split /<\d+>/, get_syslog('/e2'); |
192 | 197 |
193 # check for the presence of the syslog messages in the global and http contexts | 198 # check for the presence of the syslog messages in the global and http contexts |
194 | 199 |
195 is_deeply(levels($t, 's_glob.log'), levels($t, 'f_glob.log'), 'master syslog'); | 200 is_deeply(levels($t, 's_glob.log'), levels($t, 'f_glob.log'), 'master syslog'); |
196 is_deeply(levels($t, 's_http.log'), levels($t, 'f_http.log'), 'http syslog'); | 201 is_deeply(levels($t, 's_http.log'), levels($t, 'f_http.log'), 'http syslog'); |
202 | |
203 http_get('/if'); | |
204 http_get('/if/empty?logme='); | |
205 http_get('/if/zero?logme=0'); | |
206 http_get('/if/good?logme=1'); | |
207 http_get('/if/work?logme=yes'); | |
208 | |
209 get_syslog('/a'); | |
210 | |
211 like(read_file($t, 's_if.log'), qr/good:404.*work:404/s, 'syslog if success'); | |
212 unlike(read_file($t, 's_if.log'), qr/(if:|empty:|zero:)404/, 'syslog if fail'); | |
197 | 213 |
198 ############################################################################### | 214 ############################################################################### |
199 | 215 |
200 sub syslog_lines { | 216 sub syslog_lines { |
201 my ($uri, $pattern, $port) = @_; | 217 my ($uri, $pattern, $port) = @_; |