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