Mercurial > hg > nginx-tests
comparison syslog.t @ 467:43e05ac6c23c
Tests: the read_file function added in Test::Nginx.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 22 Sep 2014 13:30:04 +0400 |
parents | a64b4057189c |
children | 071e8941e3bf |
comparison
equal
deleted
inserted
replaced
466:a64b4057189c | 467:43e05ac6c23c |
---|---|
206 http_get('/if/good?logme=1'); | 206 http_get('/if/good?logme=1'); |
207 http_get('/if/work?logme=yes'); | 207 http_get('/if/work?logme=yes'); |
208 | 208 |
209 get_syslog('/a'); | 209 get_syslog('/a'); |
210 | 210 |
211 like(read_file($t, 's_if.log'), qr/good:404.*work:404/s, 'syslog if success'); | 211 like($t->read_file('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'); | 212 unlike($t->read_file('s_if.log'), qr/(if:|empty:|zero:)404/, 'syslog if fail'); |
213 | 213 |
214 ############################################################################### | 214 ############################################################################### |
215 | 215 |
216 sub syslog_lines { | 216 sub syslog_lines { |
217 my ($uri, $pattern, $port) = @_; | 217 my ($uri, $pattern, $port) = @_; |
220 | 220 |
221 sub levels { | 221 sub levels { |
222 my ($t, $file) = @_; | 222 my ($t, $file) = @_; |
223 my %levels_hash; | 223 my %levels_hash; |
224 | 224 |
225 map { $levels_hash{$_}++; } (read_file($t, $file) =~ /(\[\w+\])/g); | 225 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g); |
226 | 226 |
227 return \%levels_hash; | 227 return \%levels_hash; |
228 } | 228 } |
229 | 229 |
230 sub get_syslog { | 230 sub get_syslog { |
264 } | 264 } |
265 $s->close(); | 265 $s->close(); |
266 return $data; | 266 return $data; |
267 } | 267 } |
268 | 268 |
269 sub read_file { | |
270 my ($t, $file) = @_; | |
271 my $path = $t->testdir() . '/' . $file; | |
272 | |
273 open my $fh, '<', $path or return "$!"; | |
274 local $/; | |
275 my $content = <$fh>; | |
276 close $fh; | |
277 return $content; | |
278 } | |
279 | |
280 sub parse_syslog_message { | 269 sub parse_syslog_message { |
281 my ($desc, $line) = @_; | 270 my ($desc, $line) = @_; |
282 | 271 |
283 unless ($line) { | 272 unless ($line) { |
284 fail("$desc timeout in receiving syslog"); | 273 fail("$desc timeout in receiving syslog"); |