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