annotate access_log.t @ 908:adf5671391ac

Tests: use read_file subroutine in several tests.
author Andrey Zelenkov <zelenkov@nginx.com>
date Mon, 18 Apr 2016 19:29:57 +0300
parents 257de77879e8
children e9064d691790
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
2
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
3 # (C) Nginx, Inc.
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
4
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
5 # Tests for access_log.
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
6
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
7 ###############################################################################
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
8
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
9 use warnings;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
10 use strict;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
11
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
12 use Test::More;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
13
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
15
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
16 use lib 'lib';
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
18
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
19 ###############################################################################
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
20
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
23
900
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(10)
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
26
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
27 %%TEST_GLOBALS%%
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
28
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
29 daemon off;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
30
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
31 events {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
32 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
33
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
34 http {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
36
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
37 log_format test "$uri:$status";
900
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
38 log_format binary $binary_remote_addr;
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
39
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
40 server {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
41 listen 127.0.0.1:8080;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
42 server_name localhost;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
43
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
44 location /combined {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
45 access_log %%TESTDIR%%/combined.log;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
46 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
47
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
48 location /combined/off {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
49 access_log off;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
50 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
51 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
52 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
53
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
54 location /filtered {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
55 access_log %%TESTDIR%%/filtered.log test
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
56 if=$arg_logme;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
57 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
58 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
59
463
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
60 location /filtered/complex {
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
61 access_log %%TESTDIR%%/complex.log test
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
62 if=$arg_logme$arg_logmetoo;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
63 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
64 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
65
463
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
66 location /filtered/noreuse {
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
67 access_log %%TESTDIR%%/noreuse.log test buffer=16k
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
68 if=$arg_a;
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
69 access_log %%TESTDIR%%/noreuse.log test buffer=16k
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
70 if=$arg_b;
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
71 return 200 OK;
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
72 }
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
73
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
74 location /compressed {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
75 access_log %%TESTDIR%%/compressed.log test
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
76 gzip buffer=1m flush=100ms;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
77 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
78 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
79
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
80 location /multi {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
81 access_log %%TESTDIR%%/multi1.log test;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
82 access_log %%TESTDIR%%/multi2.log test;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
83 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
84 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
85
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
86 location /varlog {
616
e9f48f1e905b Tests: avoid alert/crit error logs in access_log.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 568
diff changeset
87 access_log %%TESTDIR%%/varlog_${arg_logname} test;
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
88 return 200 OK;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
89 }
900
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
90
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
91 location /binary {
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
92 access_log %%TESTDIR%%/binary.log binary;
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
93 }
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
94 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
95 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
96
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
97 EOF
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
98
568
907e89fba9c3 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 467
diff changeset
99 $t->run();
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
100
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
101 ###############################################################################
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
102
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
103 http_get('/combined');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
104 http_get('/combined/off');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
105
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
106 http_get('/filtered');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
107 http_get('/filtered/empty?logme=');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
108 http_get('/filtered/zero?logme=0');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
109 http_get('/filtered/good?logme=1');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
110 http_get('/filtered/work?logme=yes');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
111
463
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
112 http_get('/filtered/complex');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
113 http_get('/filtered/complex/one?logme=1');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
114 http_get('/filtered/complex/two?logmetoo=1');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
115 http_get('/filtered/complex/either1?logme=A&logmetoo=B');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
116 http_get('/filtered/complex/either2?logme=A');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
117 http_get('/filtered/complex/either3?logmetoo=B');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
118 http_get('/filtered/complex/either4?logme=0&logmetoo=0');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
119 http_get('/filtered/complex/neither?logme=&logmetoo=');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
120
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
121 http_get('/filtered/noreuse1/zero?a=0');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
122 http_get('/filtered/noreuse1/good?a=1');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
123 http_get('/filtered/noreuse2/zero?b=0');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
124 http_get('/filtered/noreuse2/good?b=1');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
125
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
126 http_get('/compressed');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
127
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
128 http_get('/multi');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
129
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
130 http_get('/varlog');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
131 http_get('/varlog?logname=');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
132 http_get('/varlog?logname=0');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
133 http_get('/varlog?logname=filename');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
134
900
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
135 http_get('/binary');
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
136
451
be98c162f8bc Tests: adjusted access_log test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents: 394
diff changeset
137 # wait for file to appear with nonzero size thanks to the flush parameter
be98c162f8bc Tests: adjusted access_log test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents: 394
diff changeset
138
be98c162f8bc Tests: adjusted access_log test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents: 394
diff changeset
139 for (1 .. 10) {
be98c162f8bc Tests: adjusted access_log test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents: 394
diff changeset
140 last if -s $t->testdir() . '/compressed.log';
be98c162f8bc Tests: adjusted access_log test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents: 394
diff changeset
141 select undef, undef, undef, 0.1;
be98c162f8bc Tests: adjusted access_log test timeout.
Sergey Kandaurov <pluknet@nginx.com>
parents: 394
diff changeset
142 }
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
143
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
144 # verify that "gzip" parameter turns on compression
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
145
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
146 my $log;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
147
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
148 SKIP: {
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
149 eval { require IO::Uncompress::Gunzip; };
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
150 skip("IO::Uncompress::Gunzip not installed", 1) if $@;
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
151
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 463
diff changeset
152 my $gzipped = $t->read_file('compressed.log');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
153 IO::Uncompress::Gunzip::gunzip(\$gzipped => \$log);
458
ae69f9bdba92 Tests: fixed access_log.t on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 451
diff changeset
154 like($log, qr!^/compressed:200!s, 'compressed log - flush time');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
155 }
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
156
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
157 # now verify all other logs
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
158
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
159 $t->stop();
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
160
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
161
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
162 # verify that by default, 'combined' format is used, 'off' disables logging
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
163
746
f75bc412e802 Tests: unbreak access_log tests in jails.
Sergey Kandaurov <pluknet@nginx.com>
parents: 616
diff changeset
164 my $addr = IO::Socket::INET->new(LocalAddr => '127.0.0.1')->sockhost();
f75bc412e802 Tests: unbreak access_log tests in jails.
Sergey Kandaurov <pluknet@nginx.com>
parents: 616
diff changeset
165
899
c0c2fc0e7208 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 746
diff changeset
166 like($t->read_file('combined.log'),
746
f75bc412e802 Tests: unbreak access_log tests in jails.
Sergey Kandaurov <pluknet@nginx.com>
parents: 616
diff changeset
167 qr!^\Q$addr - - [\E .*
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
168 \Q] "GET /combined HTTP/1.0" 200 2 "-" "-"\E$!x,
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
169 'default log format');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
170
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
171 # verify that log filtering works
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
172
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 463
diff changeset
173 $log = $t->read_file('filtered.log');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
174 is($log, "/filtered/good:200\n/filtered/work:200\n", 'log filtering');
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
175
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
176 # verify "if=" argument works with complex value
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
177
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
178 my $exp_complex = <<'EOF';
463
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
179 /filtered/complex/one:200
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
180 /filtered/complex/two:200
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
181 /filtered/complex/either1:200
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
182 /filtered/complex/either2:200
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
183 /filtered/complex/either3:200
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
184 /filtered/complex/either4:200
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
185 EOF
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
186
899
c0c2fc0e7208 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 746
diff changeset
187 is($t->read_file('complex.log'), $exp_complex, 'if with complex value');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
188
463
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
189 # buffer created with false "if" is not reused among multiple access_log
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
190
908
adf5671391ac Tests: use read_file subroutine in several tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 900
diff changeset
191 $log = $t->read_file('noreuse.log');
463
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
192 is($log, "/filtered/noreuse1/good:200\n/filtered/noreuse2/good:200\n",
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
193 'log filtering with buffering');
da1a459c9318 Tests: access_log "if=" tests with buffering.
Sergey Kandaurov <pluknet@nginx.com>
parents: 458
diff changeset
194
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
195 # multiple logs in a same location
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
196
899
c0c2fc0e7208 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 746
diff changeset
197 is($t->read_file('multi1.log'), "/multi:200\n", 'multiple logs 1');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
198
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
199 # same content in the second log
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
200
899
c0c2fc0e7208 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 746
diff changeset
201 is($t->read_file('multi2.log'), "/multi:200\n", 'multiple logs 2');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
202
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
203 # test log destinations with variables
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
204
899
c0c2fc0e7208 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 746
diff changeset
205 is($t->read_file('varlog_0'), "/varlog:200\n", 'varlog literal zero name');
c0c2fc0e7208 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 746
diff changeset
206 is($t->read_file('varlog_filename'), "/varlog:200\n", 'varlog good name');
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
207
900
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
208 # binary data is escaped
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
209
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
210 is($t->read_file('binary.log'), "\\x7F\\x00\\x00\\x01\n", 'binary');
257de77879e8 Tests: added access_log test with binary data.
Sergey Kandaurov <pluknet@nginx.com>
parents: 899
diff changeset
211
394
8d436291c09b Tests: added tests for the "access_log" directive.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
212 ###############################################################################