comparison gunzip_perl.t @ 231:bc1861122d0c

Tests: gunzip filter tests import.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 07 Sep 2012 20:30:32 +0400
parents
children 6a0d934950bc
comparison
equal deleted inserted replaced
230:9d7805b05f0f 231:bc1861122d0c
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for gunzip filter module with 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(qw/http gunzip perl/)->plan(2)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 server {
41 listen 127.0.0.1:8080;
42 server_name localhost;
43
44 gunzip on;
45
46 location / {
47 perl 'sub {
48 my $r = shift;
49 $r->header_out("Content-Encoding", "gzip");
50 $r->send_http_header("text/plain");
51 return OK if $r->header_only;
52 use IO::Compress::Gzip;
53 my $in = "TEST";
54 my $out;
55 IO::Compress::Gzip::gzip(\\$in => \\$out);
56 $r->print($out);
57 return OK;
58 }';
59 }
60 }
61 }
62
63 EOF
64
65 $t->run();
66
67 ###############################################################################
68
69 http_gzip_like(http_gzip_request('/'), qr/TEST/, 'perl response gzipped');
70 like(http_get('/'), qr/TEST/, 'perl response gunzipped');
71
72 ###############################################################################