comparison access_log.t @ 467:43e05ac6c23c

Tests: the read_file function added in Test::Nginx.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 22 Sep 2014 13:30:04 +0400
parents da1a459c9318
children 907e89fba9c3
comparison
equal deleted inserted replaced
466:a64b4057189c 467:43e05ac6c23c
141 141
142 SKIP: { 142 SKIP: {
143 eval { require IO::Uncompress::Gunzip; }; 143 eval { require IO::Uncompress::Gunzip; };
144 skip("IO::Uncompress::Gunzip not installed", 1) if $@; 144 skip("IO::Uncompress::Gunzip not installed", 1) if $@;
145 145
146 my $gzipped = read_file($t, 'compressed.log'); 146 my $gzipped = $t->read_file('compressed.log');
147 IO::Uncompress::Gunzip::gunzip(\$gzipped => \$log); 147 IO::Uncompress::Gunzip::gunzip(\$gzipped => \$log);
148 like($log, qr!^/compressed:200!s, 'compressed log - flush time'); 148 like($log, qr!^/compressed:200!s, 'compressed log - flush time');
149 } 149 }
150 150
151 # now verify all other logs 151 # now verify all other logs
153 $t->stop(); 153 $t->stop();
154 154
155 155
156 # verify that by default, 'combined' format is used, 'off' disables logging 156 # verify that by default, 'combined' format is used, 'off' disables logging
157 157
158 $log = read_file($t, 'combined.log'); 158 $log = $t->read_file('combined.log');
159 like($log, 159 like($log,
160 qr!^\Q127.0.0.1 - - [\E .* 160 qr!^\Q127.0.0.1 - - [\E .*
161 \Q] "GET /combined HTTP/1.0" 200 2 "-" "-"\E$!x, 161 \Q] "GET /combined HTTP/1.0" 200 2 "-" "-"\E$!x,
162 'default log format'); 162 'default log format');
163 163
164 # verify that log filtering works 164 # verify that log filtering works
165 165
166 $log = read_file($t, 'filtered.log'); 166 $log = $t->read_file('filtered.log');
167 is($log, "/filtered/good:200\n/filtered/work:200\n", 'log filtering'); 167 is($log, "/filtered/good:200\n/filtered/work:200\n", 'log filtering');
168 168
169 169
170 # verify "if=" argument works with complex value 170 # verify "if=" argument works with complex value
171 171
176 /filtered/complex/either2:200 176 /filtered/complex/either2:200
177 /filtered/complex/either3:200 177 /filtered/complex/either3:200
178 /filtered/complex/either4:200 178 /filtered/complex/either4:200
179 EOF 179 EOF
180 180
181 $log = read_file($t, 'complex.log'); 181 $log = $t->read_file('complex.log');
182 is($log, $exp_complex, 'if with complex value'); 182 is($log, $exp_complex, 'if with complex value');
183 183
184 184
185 # buffer created with false "if" is not reused among multiple access_log 185 # buffer created with false "if" is not reused among multiple access_log
186 186
187 TODO: { 187 TODO: {
188 local $TODO = 'not yet' unless $t->has_version('1.7.5'); 188 local $TODO = 'not yet' unless $t->has_version('1.7.5');
189 189
190 $log = read_file($t, '/noreuse.log'); 190 $log = $t->read_file('/noreuse.log');
191 is($log, "/filtered/noreuse1/good:200\n/filtered/noreuse2/good:200\n", 191 is($log, "/filtered/noreuse1/good:200\n/filtered/noreuse2/good:200\n",
192 'log filtering with buffering'); 192 'log filtering with buffering');
193 193
194 } 194 }
195 195
196 196
197 # multiple logs in a same location 197 # multiple logs in a same location
198 198
199 $log = read_file($t, 'multi1.log'); 199 $log = $t->read_file('multi1.log');
200 is($log, "/multi:200\n", 'multiple logs 1'); 200 is($log, "/multi:200\n", 'multiple logs 1');
201 201
202 # same content in the second log 202 # same content in the second log
203 203
204 $log = read_file($t, 'multi2.log'); 204 $log = $t->read_file('multi2.log');
205 is($log, "/multi:200\n", 'multiple logs 2'); 205 is($log, "/multi:200\n", 'multiple logs 2');
206 206
207 207
208 # test log destinations with variables 208 # test log destinations with variables
209 209
210 $log = read_file($t, '0'); 210 $log = $t->read_file('0');
211 is($log, "/varlog:200\n", 'varlog literal zero name'); 211 is($log, "/varlog:200\n", 'varlog literal zero name');
212 212
213 $log = read_file($t, 'filename'); 213 $log = $t->read_file('filename');
214 is($log, "/varlog:200\n", 'varlog good name'); 214 is($log, "/varlog:200\n", 'varlog good name');
215 215
216 ############################################################################### 216 ###############################################################################
217
218 sub read_file {
219 my ($t, $file) = @_;
220 my $path = $t->testdir() . '/' . $file;
221
222 open my $fh, '<', $path or return "$!";
223 local $/;
224 my $content = <$fh>;
225 close $fh;
226 return $content;
227 }
228
229 ###############################################################################