comparison gunzip.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 6a0d934950bc
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.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx qw/ :DEFAULT :gzip /;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 eval { require IO::Compress::Gzip; };
25 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@;
26
27 my $t = Test::Nginx->new()->has(qw/http gunzip proxy gzip_static/)->plan(13);
28
29 $t->write_file_expand('nginx.conf', <<'EOF');
30
31 %%TEST_GLOBALS%%
32
33 daemon off;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44 location / {
45 gunzip on;
46 gzip_vary on;
47 proxy_pass http://127.0.0.1:8081/;
48 proxy_set_header Accept-Encoding gzip;
49 }
50 location /error {
51 error_page 500 /t1;
52 return 500;
53 }
54 }
55
56 server {
57 listen 127.0.0.1:8081;
58 server_name localhost;
59
60 location / {
61 default_type text/plain;
62 gzip_static on;
63 gzip_http_version 1.0;
64 gzip_types text/plain;
65 }
66 }
67 }
68
69 EOF
70
71 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99));
72 my $out;
73
74 IO::Compress::Gzip::gzip(\$in => \$out);
75
76 $t->write_file('t1.gz', $out);
77 $t->write_file('t2.gz', $out . $out);
78 $t->write_file('t3', 'not compressed');
79
80 my $emptyin = '';
81 my $emptyout;
82 IO::Compress::Gzip::gzip(\$emptyin => \$emptyout);
83
84 $t->write_file('empty.gz', $emptyout);
85
86 $t->run();
87
88 ###############################################################################
89
90 pass('runs');
91
92 my $r = http_get('/t1');
93 unlike($r, qr/Content-Encoding/, 'no content encoding');
94 like($r, qr/^(X\d\d\dXXXXXX){100}$/m, 'correct gunzipped response');
95
96 $r = http_gzip_request('/t1');
97 like($r, qr/Content-Encoding: gzip/, 'gzip still works - encoding');
98 like($r, qr/\Q$out\E/, 'gzip still works - content');
99
100 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members');
101
102 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors gunzipped');
103
104 unlike(http_head('/t1'), qr/Content-Encoding/, 'head - no content encoding');
105
106 like(http_get('/t1'), qr/Vary/, 'get vary');
107 like(http_head('/t1'), qr/Vary/, 'head vary');
108 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get');
109 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head');
110
111 like(http_get('/empty'), qr/ 200 /, 'gunzip empty');
112
113 ###############################################################################