annotate syslog.t @ 507:34280f6b0bc6

Tests: trailing spaces.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 02 Dec 2014 21:08:34 +0300
parents 071e8941e3bf
children 907e89fba9c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Nginx, Inc.
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # Tests for syslog.
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Various log levels emitted with limit_req_log_level.
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
408
82b15c81978e Tests: skipped tests on win32 that use shared memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 404
diff changeset
25 plan(skip_all => 'win32') if $^O eq 'MSWin32';
82b15c81978e Tests: skipped tests on win32 that use shared memory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 404
diff changeset
26
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http limit_req/);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
29 plan(skip_all => 'no syslog if') unless $t->has_version('1.7.5');
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
31 $t->plan(58)->write_file_expand('nginx.conf', <<'EOF');
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 %%TEST_GLOBALS%%
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 error_log syslog:server=127.0.0.1:8083 info;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 error_log %%TESTDIR%%/f_glob.log info;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 daemon off;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 events {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 http {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 %%TEST_GLOBALS_HTTP%%
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
503
071e8941e3bf Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 467
diff changeset
46 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m;
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 log_format empty "";
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
49 log_format logf "$uri:$status";
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 error_log syslog:server=127.0.0.1:8084 info;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 error_log %%TESTDIR%%/f_http.log info;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 listen 127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 server_name localhost;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 location /e {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 location /a {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 access_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 location /ef {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 error_log syslog:server=127.0.0.1:8080,facility=user;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 location /es {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 error_log syslog:server=127.0.0.1:8080,severity=alert;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 location /et {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 error_log syslog:server=127.0.0.1:8080,tag=SEETHIS;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 location /af {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 access_log syslog:server=127.0.0.1:8080,facility=user;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 location /as {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 access_log syslog:server=127.0.0.1:8080,severity=alert;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 location /at {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 access_log syslog:server=127.0.0.1:8080,tag=SEETHIS;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 location /e2 {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 location /a2 {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 access_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 access_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 location /a_logf {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 access_log syslog:server=127.0.0.1:8080 logf;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 }
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
93 location /if {
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
94 access_log syslog:server=127.0.0.1:8085 logf if=$arg_logme;
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
95 }
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 location /debug {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 limit_req zone=one;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 error_log syslog:server=127.0.0.1:8080 debug;
507
34280f6b0bc6 Tests: trailing spaces.
Maxim Dounin <mdounin@mdounin.ru>
parents: 503
diff changeset
100 }
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 location /info {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 limit_req zone=one;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 limit_req_log_level info;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 error_log syslog:server=127.0.0.1:8080 info;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 location /notice {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 limit_req zone=one;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 limit_req_log_level notice;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 error_log syslog:server=127.0.0.1:8080 notice;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 location /warn {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 limit_req zone=one;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 limit_req_log_level warn;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 error_log syslog:server=127.0.0.1:8080 warn;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 location /error {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 limit_req zone=one;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 limit_req_log_level error;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 location /low {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 error_log syslog:server=127.0.0.1:8080 warn;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 location /dup {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 location /high {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 error_log syslog:server=127.0.0.1:8080 emerg;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 error_log syslog:server=127.0.0.1:8080;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 EOF
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 $t->run_daemon(\&syslog_daemon, 8083, $t, 's_glob.log');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 $t->run_daemon(\&syslog_daemon, 8084, $t, 's_http.log');
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
140 $t->run_daemon(\&syslog_daemon, 8085, $t, 's_if.log');
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 $t->waitforfile($t->testdir . '/s_glob.log');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 $t->waitforfile($t->testdir . '/s_http.log');
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
144 $t->waitforfile($t->testdir . '/s_if.log');
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 $t->run();
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 ###############################################################################
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 parse_syslog_message('error_log', get_syslog('/e'));
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 parse_syslog_message('access_log', get_syslog('/a'));
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 like(get_syslog('/ef'), qr/^<11>/, 'error_log facility');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 like(get_syslog('/es'), qr/^<187>/, 'error_log severity');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 like(get_syslog('/et'), qr/SEETHIS:/, 'error_log tag');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 like(get_syslog('/af'), qr/^<14>/, 'access_log facility');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 like(get_syslog('/as'), qr/^<185>/, 'access_log severity');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 like(get_syslog('/at'), qr/SEETHIS:/, 'access_log tag');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 like(get_syslog('/e'),
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 qr/nginx: \d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2} \[error\]/,
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 'error_log format');
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
165 like(get_syslog('/a_logf'), qr/nginx: \/a_logf:404$/, 'access_log log_format');
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 my @lines = split /<\d+>/, get_syslog('/a2');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 is($lines[1], $lines[2], 'access_log many');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 @lines = split /<\d+>/, get_syslog('/e2');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 is($lines[1], $lines[2], 'error_log many');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 # error_log log levels
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 SKIP: {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 skip "no --with-debug", 1 unless $t->has_module('--with-debug');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 isnt(syslog_lines('/debug', '[debug]'), 0, 'debug');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 # charge limit_req
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 get_syslog('/info');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 is(syslog_lines('/info', '[info]'), 1, 'info');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 is(syslog_lines('/notice', '[notice]'), 1, 'notice');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 is(syslog_lines('/warn', '[warn]'), 1, 'warn');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 is(syslog_lines('/error', '[error]'), 1, 'error');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 # count log messages emitted with various error_log levels
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 is(syslog_lines('/low', '[error]'), 2, 'low');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 is(syslog_lines('/dup', '[error]'), 2, 'dup');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 is(syslog_lines('/high', '[error'), 1, 'high');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 # check for the presence of the syslog messages in the global and http contexts
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 is_deeply(levels($t, 's_glob.log'), levels($t, 'f_glob.log'), 'master syslog');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 is_deeply(levels($t, 's_http.log'), levels($t, 'f_http.log'), 'http syslog');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
203 http_get('/if');
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
204 http_get('/if/empty?logme=');
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
205 http_get('/if/zero?logme=0');
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
206 http_get('/if/good?logme=1');
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
207 http_get('/if/work?logme=yes');
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
208
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
209 get_syslog('/a');
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
210
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 466
diff changeset
211 like($t->read_file('s_if.log'), qr/good:404.*work:404/s, 'syslog if success');
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 466
diff changeset
212 unlike($t->read_file('s_if.log'), qr/(if:|empty:|zero:)404/, 'syslog if fail');
445
62d1f96c5ff4 Tests: syslog "if=" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 408
diff changeset
213
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 ###############################################################################
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216 sub syslog_lines {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 my ($uri, $pattern, $port) = @_;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 return map { $_ =~ /\Q$pattern\E/g } (get_syslog($uri, $port));
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 sub levels {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 my ($t, $file) = @_;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 my %levels_hash;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 466
diff changeset
225 map { $levels_hash{$_}++; } ($t->read_file($file) =~ /(\[\w+\])/g);
404
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 return \%levels_hash;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 sub get_syslog {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 my ($uri, $port) = @_;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 my ($s);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 my $rfd = '';
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 my $data = '';
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 $port = 8080 unless defined $port;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238 eval {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 local $SIG{ALRM} = sub { die "timeout\n" };
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 local $SIG{PIPE} = sub { die "sigpipe\n" };
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241 alarm(1);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 $s = IO::Socket::INET->new(
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 Proto => 'udp',
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 LocalAddr => "127.0.0.1:$port"
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 );
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 alarm(0);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 };
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 alarm(0);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 if ($@) {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 log_in("died: $@");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 return undef;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 http_get($uri);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 vec($rfd, fileno($s), 1) = 1;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 select $rfd, undef, undef, 1;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 while (select($rfd, undef, undef, 0.1) > 0
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 && vec($rfd, fileno($s), 1))
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 my $buffer;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 sysread($s, $buffer, 4096);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 $data .= $buffer;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 $s->close();
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 return $data;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269 sub parse_syslog_message {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270 my ($desc, $line) = @_;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272 unless ($line) {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 fail("$desc timeout in receiving syslog");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276 my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277 'Sep', 'Oct', 'Nov', 'Dec');
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279 my ($pri, $mon, $mday, $hour, $minute, $sec, $host, $tag, $msg) =
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 $line =~ /^<(\d{1,3})> # PRI
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 ([A-Z][a-z]{2})\s # mon
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 ([ \d]\d)\s(\d{2}):(\d{2}):(\d{2})\s # date
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 ([\S]*)\s # host
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 (\w{1,32}):\s # tag
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285 (.*)/x; # MSG
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287 my $sev = $pri & 0x07;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 my $fac = ($pri & 0x03f8) >> 3;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 ok(defined($pri), "$desc has PRI");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291 ok($sev >= 0 && $sev <= 7, "$desc valid severity");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292 ok($fac >= 0 && $fac < 24, "$desc valid facility");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 ok(defined($mon), "$desc has month");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 ok((grep $mon, @months), "$desc valid month");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 ok(defined($mday), "$desc has day");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298 ok($mday <= 31, "$desc valid day");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 ok(defined($hour), "$desc has hour");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 ok($hour < 24, "$desc valid hour");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
303 ok(defined($minute), "$desc has minutes");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304 ok($minute < 60, "$desc valid minutes");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 ok(defined($sec), "$desc has seconds");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 ok($sec < 60, "$desc valid seconds");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 ok(defined($host), "$desc has host");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 chomp(my $hostname = lc `hostname`);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 is($host , $hostname, "$desc valid host");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 ok(defined($tag), "$desc has tag");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 like($tag, qr'\w+', "$desc valid tag");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 ok(length($msg) > 0, "$desc valid CONTENT");
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 ###############################################################################
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 sub syslog_daemon {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 my ($port, $t, $file) = @_;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 my $s = IO::Socket::INET->new(
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 Proto => 'udp',
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326 LocalAddr => "127.0.0.1:$port"
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 );
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 open my $fh, '>', $t->testdir() . '/' . $file;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330 select $fh; $| = 1;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 while (1) {
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 my $buffer;
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 $s->recv($buffer, 4096);
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 print $fh $buffer . "\n";
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337 }
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338
997f5fe16545 Tests: added syslog tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 ###############################################################################