Mercurial > hg > nginx-tests
annotate perl_gzip.t @ 165:fca70f483608
Tests: fix previous commit (print original message length).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 01 Aug 2011 21:50:01 +0400 |
parents | b714d6df958c |
children | c0ae29632905 |
rev | line source |
---|---|
118
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for embedded perl module. |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx qw/ :DEFAULT :gzip /; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 eval { require IO::Compress::Gzip; }; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
118
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http perl gzip/)->plan(2) |
118
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 master_process off; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 daemon off; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 events { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 http { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server_name localhost; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 gzip on; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 gzip_types text/plain; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 location / { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 perl 'sub { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 my $r = shift; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 $r->send_http_header("text/plain"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 return OK if $r->header_only; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 $r->print("TEST"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 return OK; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 }'; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 location /gz { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 perl 'sub { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 my $r = shift; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $r->header_out("Content-Encoding", "gzip"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 $r->send_http_header("text/plain"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 return OK if $r->header_only; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 use IO::Compress::Gzip; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 my $in = "TEST"; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 my $out; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 IO::Compress::Gzip::gzip(\\$in => \\$out); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 $r->print($out); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 return OK; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 }'; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 EOF |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 $t->run(); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 ############################################################################### |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 http_gzip_like(http_gzip_request('/'), qr/TEST/, 'perl response gzipped'); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 TODO: { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 local $TODO = 'patch pending'; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 http_gzip_like(http_gzip_request('/gz'), qr/TEST/, 'not doublegzipped'); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 } |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 ############################################################################### |