Mercurial > hg > ngx_http_gunzip_filter_module
annotate t/gunzip.t @ 7:9158103f8571 0.1
Gunzip: fix tests for repcached and memcached 1.2.7+.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 28 Dec 2009 14:45:12 +0000 |
parents | 7170c171150c |
children | b12d2ee20755 |
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 | |
3
7170c171150c
Gunzip: better test dependencies.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
23 my $t = Test::Nginx->new()->has(qw/http proxy gzip_static/)->plan(12); |
0 | 24 |
25 $t->write_file_expand('nginx.conf', <<'EOF'); | |
26 | |
27 master_process off; | |
28 daemon off; | |
29 | |
30 events { | |
31 } | |
32 | |
33 http { | |
34 access_log off; | |
35 root %%TESTDIR%%; | |
36 | |
37 client_body_temp_path %%TESTDIR%%/client_body_temp; | |
38 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; | |
39 proxy_temp_path %%TESTDIR%%/proxy_temp; | |
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 $t->run(); | |
81 | |
82 ############################################################################### | |
83 | |
84 pass('runs'); | |
85 | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
86 my $r = http_get('/t1'); |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
87 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
|
88 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
|
89 |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
90 $r = http_gzip_request('/t1'); |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
91 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
|
92 like($r, qr/\Q$out\E/, 'gzip still works - content'); |
0 | 93 |
94 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members'); | |
95 | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
96 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors gunzipped'); |
0 | 97 |
98 unlike(http_head('/t1'), qr/Content-Encoding/, 'head - no content encoding'); | |
99 | |
100 like(http_get('/t1'), qr/Vary/, 'get vary'); | |
101 like(http_head('/t1'), qr/Vary/, 'head vary'); | |
102 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get'); | |
103 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head'); | |
104 | |
105 ############################################################################### |