comparison gunzip_static.t @ 231:bc1861122d0c

Tests: gunzip filter tests import.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 07 Sep 2012 20:30:32 +0400
parents
children 96387f409880
comparison
equal deleted inserted replaced
230:9d7805b05f0f 231:bc1861122d0c
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for gunzip filter module with gzip_static always. It is basically
6 # the copy of gunzip.t with minor modifications.
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 qw/ :DEFAULT :gzip /;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 eval { require IO::Compress::Gzip; };
26 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@;
27
28 my $t = Test::Nginx->new()->has(qw/http gunzip proxy gzip_static/);
29
30 $t->write_file_expand('nginx.conf', <<'EOF');
31
32 %%TEST_GLOBALS%%
33
34 daemon off;
35
36 events {
37 }
38
39 http {
40 %%TEST_GLOBALS_HTTP%%
41
42 server {
43 listen 127.0.0.1:8080;
44 server_name localhost;
45 location / {
46 gunzip on;
47 gzip_vary on;
48 gzip_static always;
49 }
50 location /error {
51 error_page 500 /t1;
52 return 500;
53 }
54 }
55 }
56
57 EOF
58
59 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99));
60 my $out;
61
62 IO::Compress::Gzip::gzip(\$in => \$out);
63
64 $t->write_file('t1.gz', $out);
65 $t->write_file('t2.gz', $out . $out);
66 $t->write_file('t3', 'not compressed');
67
68 eval {
69 open OLDERR, ">&", \*STDERR; close STDERR;
70 $t->run();
71 open STDERR, ">&", \*OLDERR;
72 };
73 plan(skip_all => 'no gzip_static always') if $@;
74
75 $t->plan(12);
76
77 ###############################################################################
78
79 pass('runs');
80
81 my $r = http_get('/t1');
82 unlike($r, qr/Content-Encoding/, 'no content encoding');
83 like($r, qr/^(X\d\d\dXXXXXX){100}$/m, 'correct gunzipped response');
84
85 $r = http_gzip_request('/t1');
86 like($r, qr/Content-Encoding: gzip/, 'gzip still works - encoding');
87 like($r, qr/\Q$out\E/, 'gzip still works - content');
88
89 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members');
90
91 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors gunzipped');
92
93 unlike(http_head('/t1'), qr/Content-Encoding/, 'head - no content encoding');
94
95 like(http_get('/t1'), qr/Vary/, 'get vary');
96 like(http_head('/t1'), qr/Vary/, 'head vary');
97 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get');
98 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head');
99
100 ###############################################################################