Mercurial > hg > ngx_http_gunzip_filter_module
annotate t/gunzip-static.t @ 4:2698bf018167
Gunzip: add tests for replies from gzip_static always.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 27 Dec 2009 03:45:37 +0300 |
parents | t/gunzip.t@7170c171150c |
children |
rev | line source |
---|---|
0 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
4
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
5 # Tests for gunzip filter module with gzip_static always. It is basically |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
6 # the copy of gunzip.t with minor modifications. |
0 | 7 |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
14 use Test::Nginx qw/ :DEFAULT :gzip /; |
0 | 15 |
16 ############################################################################### | |
17 | |
18 select STDERR; $| = 1; | |
19 select STDOUT; $| = 1; | |
20 | |
21 eval { require IO::Compress::Gzip; }; | |
22 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@; | |
23 | |
4
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy gzip_static/); |
0 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 master_process off; | |
29 daemon off; | |
30 | |
31 events { | |
32 } | |
33 | |
34 http { | |
35 access_log off; | |
36 root %%TESTDIR%%; | |
37 | |
38 client_body_temp_path %%TESTDIR%%/client_body_temp; | |
39 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; | |
40 proxy_temp_path %%TESTDIR%%/proxy_temp; | |
41 | |
42 server { | |
43 listen 127.0.0.1:8080; | |
44 server_name localhost; | |
45 location / { | |
46 gunzip on; | |
47 gzip_vary on; | |
4
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
48 gzip_static always; |
0 | 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 | |
4
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
68 eval { |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
69 open OLDERR, ">&", \*STDERR; close STDERR; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
70 $t->run(); |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
71 open STDERR, ">&", \*OLDERR; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
72 }; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
73 plan(skip_all => 'no gzip_static always') if $@; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
74 |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
75 $t->plan(12); |
0 | 76 |
77 ############################################################################### | |
78 | |
79 pass('runs'); | |
80 | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
81 my $r = http_get('/t1'); |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
82 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
|
83 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
|
84 |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
85 $r = http_gzip_request('/t1'); |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
86 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
|
87 like($r, qr/\Q$out\E/, 'gzip still works - content'); |
0 | 88 |
89 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members'); | |
90 | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
91 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors gunzipped'); |
0 | 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 ############################################################################### |