Mercurial > hg > ngx_http_gunzip_filter_module
annotate t/gunzip_static.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 | 1adc6718cc05 |
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 | |
21 | 24 my $t = Test::Nginx->new()->has(qw/http gunzip proxy gzip_static/); |
0 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
21 | 28 %%TEST_GLOBALS%% |
29 | |
0 | 30 daemon off; |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
21 | 36 %%TEST_GLOBALS_HTTP%% |
0 | 37 |
38 server { | |
39 listen 127.0.0.1:8080; | |
40 server_name localhost; | |
41 location / { | |
42 gunzip on; | |
43 gzip_vary on; | |
4
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
44 gzip_static always; |
0 | 45 } |
46 location /error { | |
47 error_page 500 /t1; | |
48 return 500; | |
49 } | |
50 } | |
51 } | |
52 | |
53 EOF | |
54 | |
55 my $in = join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99)); | |
56 my $out; | |
57 | |
58 IO::Compress::Gzip::gzip(\$in => \$out); | |
59 | |
60 $t->write_file('t1.gz', $out); | |
61 $t->write_file('t2.gz', $out . $out); | |
62 $t->write_file('t3', 'not compressed'); | |
63 | |
4
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
64 eval { |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
65 open OLDERR, ">&", \*STDERR; close STDERR; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
66 $t->run(); |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
67 open STDERR, ">&", \*OLDERR; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
68 }; |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
69 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
|
70 |
2698bf018167
Gunzip: add tests for replies from gzip_static always.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3
diff
changeset
|
71 $t->plan(12); |
0 | 72 |
73 ############################################################################### | |
74 | |
75 pass('runs'); | |
76 | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
77 my $r = http_get('/t1'); |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
78 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
|
79 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
|
80 |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
81 $r = http_gzip_request('/t1'); |
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
82 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
|
83 like($r, qr/\Q$out\E/, 'gzip still works - content'); |
0 | 84 |
85 like(http_get('/t2'), qr/^(X\d\d\dXXXXXX){200}$/m, 'multiple gzip members'); | |
86 | |
1
0dd7d109e56b
Gunzip: add more tests and improve docs.
Maxim Dounin <mdounin@mdounin.ru>
parents:
0
diff
changeset
|
87 like(http_get('/error'), qr/^(X\d\d\dXXXXXX){100}$/m, 'errors gunzipped'); |
0 | 88 |
89 unlike(http_head('/t1'), qr/Content-Encoding/, 'head - no content encoding'); | |
90 | |
91 like(http_get('/t1'), qr/Vary/, 'get vary'); | |
92 like(http_head('/t1'), qr/Vary/, 'head vary'); | |
93 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get'); | |
94 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head'); | |
95 | |
96 ############################################################################### |