annotate mail_error_log.t @ 566:4296379213c8

Tests: refactored stream least_conn tests similar to e4ff43e00d84.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 29 Apr 2015 15:53:58 +0300
parents a1c93746570d
children adbb9b5108aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
564
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for nginx mail imap module, error_log directive.
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::IMAP;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 plan(skip_all => 'win32') if $^O eq 'MSWin32';
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 my $t = Test::Nginx->new()->has(qw/mail imap http rewrite/)
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 ->run_daemon(\&Test::Nginx::IMAP::imap_test_daemon);
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 plan(skip_all => 'no error_log') unless $t->has_version('1.9.0');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 $t->plan(29)->write_file_expand('nginx.conf', <<'EOF');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 %%TEST_GLOBALS%%
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 error_log %%TESTDIR%%/e_glob.log info;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 error_log %%TESTDIR%%/e_glob2.log info;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 error_log syslog:server=127.0.0.1:8081 info;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 daemon off;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 events {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 mail {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 auth_http http://127.0.0.1:8080/mail/auth;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 server {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 listen 127.0.0.1:8143;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 protocol imap;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 error_log %%TESTDIR%%/e_debug.log debug;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 error_log %%TESTDIR%%/e_info.log info;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 error_log syslog:server=127.0.0.1:8082 info;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 error_log stderr info;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 http {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 %%TEST_GLOBALS_HTTP%%
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 server {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 listen 127.0.0.1:8080;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 server_name localhost;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 location = /mail/auth {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 add_header Auth-Status OK;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 add_header Auth-Server 127.0.0.1;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 add_header Auth-Port 8144;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 add_header Auth-Wait 1;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 return 204;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 EOF
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 open OLDERR, ">&", \*STDERR;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 open STDERR, '>', $t->testdir() . '/stderr' or die "Can't reopen STDERR: $!";
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 open my $stderr, '<', $t->testdir() . '/stderr'
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 or die "Can't open stderr file: $!";
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 $t->run_daemon(\&syslog_daemon, 8081, $t, 's_glob.log');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 $t->run_daemon(\&syslog_daemon, 8082, $t, 's_info.log');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 $t->waitforfile($t->testdir . '/s_glob.log');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 $t->waitforfile($t->testdir . '/s_info.log');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 $t->run();
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 open STDERR, ">&", \*OLDERR;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 ###############################################################################
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my $s = Test::Nginx::IMAP->new();
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 $s->ok('greeting');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 # error_log levels
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 SKIP: {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 skip "no --with-debug", 1 unless $t->has_module('--with-debug');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 isnt(lines($t, 'e_debug.log', '[debug]'), 0, 'file debug in debug');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 isnt(lines($t, 'e_info.log', '[info]'), 0, 'file info in info');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 is(lines($t, 'e_info.log', '[debug]'), 0, 'file debug in info');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 isnt(lines($t, 'stderr', '[info]'), 0, 'stderr info in info');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 is(lines($t, 'stderr', '[debug]'), 0, 'stderr debug in info');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 # multiple error_log
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 like($t->read_file('e_glob.log'), qr!nginx/[.0-9]+!, 'error global');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 like($t->read_file('e_glob2.log'), qr!nginx/[.0-9]+!, 'error global 2');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 is_deeply(levels($t, 'e_glob.log'), levels($t, 'e_glob2.log'),
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 'multiple error global');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 # syslog
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 parse_syslog_message('syslog', $t->read_file('s_info.log'));
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 is_deeply(levels($t, 's_glob.log'), levels($t, 'e_glob.log'),
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 'global syslog messages');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 is_deeply(levels($t, 's_info.log'), levels($t, 'e_info.log'),
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 'mail syslog messages');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 ###############################################################################
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 sub lines {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 my ($t, $file, $pattern) = @_;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 if ($file eq 'stderr') {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 return map { $_ =~ /\Q$pattern\E/ } (<$stderr>);
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 my $path = $t->testdir() . '/' . $file;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 open my $fh, '<', $path or return "$!";
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 my $value = map { $_ =~ /\Q$pattern\E/ } (<$fh>);
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 close $fh;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 return $value;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 sub levels {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 my ($t, $file) = @_;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 my %levels_hash;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g);
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 return \%levels_hash;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 sub parse_syslog_message {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 my ($desc, $line) = @_;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 'Sep', 'Oct', 'Nov', 'Dec');
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) =
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 $line =~ /^<(\d{1,3})> # PRI
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 ([A-Z][a-z]{2})\s # mon
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 ([ \d]\d)\s(\d{2}):(\d{2}):(\d{2})\s # date
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 ([\S]*)\s # host
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 (\w{1,32}):\s # tag
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 (.*)/x; # MSG
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 my $sev = $pri & 0x07;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 my $fac = ($pri & 0x03f8) >> 3;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 ok(defined($pri), "$desc has PRI");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 ok($sev >= 0 && $sev <= 7, "$desc valid severity");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 ok($fac >= 0 && $fac < 24, "$desc valid facility");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 ok(defined($mon), "$desc has month");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 ok((grep $mon, @months), "$desc valid month");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 ok(defined($mday), "$desc has day");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 ok($mday <= 31, "$desc valid day");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 ok(defined($hour), "$desc has hour");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 ok($hour < 24, "$desc valid hour");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 ok(defined($minute), "$desc has minutes");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 ok($minute < 60, "$desc valid minutes");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 ok(defined($sec), "$desc has seconds");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 ok($sec < 60, "$desc valid seconds");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 ok(defined($host), "$desc has host");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 chomp(my $hostname = lc `hostname`);
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 is($host , $hostname, "$desc valid host");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 ok(defined($tag), "$desc has tag");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 like($tag, qr'\w+', "$desc valid tag");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 ok(length($msg) > 0, "$desc valid CONTENT");
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 ###############################################################################
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 sub syslog_daemon {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 my ($port, $t, $file) = @_;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 my $s = IO::Socket::INET->new(
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 Proto => 'udp',
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 LocalAddr => "127.0.0.1:$port"
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 );
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 open my $fh, '>', $t->testdir() . '/' . $file;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211 select $fh; $| = 1;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 while (1) {
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 my $buffer;
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215 $s->recv($buffer, 4096);
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216 print $fh $buffer . "\n";
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 }
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219
a1c93746570d Tests: mail error_log tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 ###############################################################################