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