Mercurial > hg > nginx-tests
comparison access_log_variables.t @ 701:bae890b8828d
Tests: added tests for log module variables.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Fri, 18 Sep 2015 15:52:14 +0300 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
700:e28787665f99 | 701:bae890b8828d |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Andrey Zelenkov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for log module variables. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(6) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 log_format time_iso8601 '$uri $time_iso8601'; | |
39 log_format time_local '$uri $time_local'; | |
40 log_format msec '$uri $msec'; | |
41 log_format request '$uri $status $request_length $request_time'; | |
42 log_format bytes '$uri $bytes_sent $body_bytes_sent'; | |
43 log_format pipe '$uri $pipe'; | |
44 | |
45 server { | |
46 listen 127.0.0.1:8080; | |
47 server_name localhost; | |
48 | |
49 location /iso8601 { | |
50 access_log %%TESTDIR%%/iso8601.log time_iso8601; | |
51 return 200; | |
52 } | |
53 | |
54 location /local { | |
55 access_log %%TESTDIR%%/local.log time_local; | |
56 return 200; | |
57 } | |
58 | |
59 location /msec { | |
60 access_log %%TESTDIR%%/msec.log msec; | |
61 return 200; | |
62 } | |
63 | |
64 location /request { | |
65 access_log %%TESTDIR%%/request.log request; | |
66 return 200; | |
67 } | |
68 | |
69 location /bytes { | |
70 access_log %%TESTDIR%%/bytes.log bytes; | |
71 return 200 OK; | |
72 } | |
73 | |
74 location /pipe { | |
75 access_log %%TESTDIR%%/pipe.log pipe; | |
76 return 200; | |
77 } | |
78 } | |
79 } | |
80 | |
81 EOF | |
82 | |
83 $t->run(); | |
84 | |
85 ############################################################################### | |
86 | |
87 http_get('/iso8601'); | |
88 http_get('/local'); | |
89 http_get('/msec'); | |
90 http_get('/request'); | |
91 my $bytes_sent = length http_get('/bytes'); | |
92 | |
93 # pipelined requests | |
94 | |
95 http(<<EOF); | |
96 GET /pipe HTTP/1.1 | |
97 Host: localhost | |
98 | |
99 GET /pipe HTTP/1.1 | |
100 Host: localhost | |
101 Connection: close | |
102 | |
103 EOF | |
104 | |
105 $t->stop(); | |
106 | |
107 my $log = $t->read_file('iso8601.log'); | |
108 like($log, qr!/iso8601 \d{4}-\d\d-\d\dT\d\d:\d\d:\d\d[+-]\d\d:\d\d!, | |
109 'time_iso8601'); | |
110 | |
111 $log = $t->read_file('local.log'); | |
112 like($log, qr!/local \d\d/[A-Z][a-z]{2}/\d{4}:\d\d:\d\d:\d\d [+-]\d{4}!, | |
113 'time_local'); | |
114 | |
115 $log = $t->read_file('msec.log'); | |
116 like($log, qr!/msec [\d\.]+!, 'msec'); | |
117 | |
118 $log = $t->read_file('request.log'); | |
119 like($log, qr!/request 200 39 [\d\.]+!, 'request'); | |
120 | |
121 $log = $t->read_file('bytes.log'); | |
122 is($log, "/bytes $bytes_sent 2\n", 'bytes sent'); | |
123 | |
124 $log = $t->read_file('pipe.log'); | |
125 is($log, "/pipe .\n/pipe p\n", 'pipe'); | |
126 | |
127 ############################################################################### |