Mercurial > hg > nginx-tests
annotate perl_gzip.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
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; }; |
773 | 25 plan(skip_all => "IO::Compress::Gzip not found") if $@; |
118
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 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
181
diff
changeset
|
32 daemon off; |
118
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
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 http { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
118
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server_name localhost; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 gzip on; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 gzip_types text/plain; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 location / { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 perl 'sub { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 my $r = shift; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 $r->send_http_header("text/plain"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 return OK if $r->header_only; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 $r->print("TEST"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 return OK; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 }'; |
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 location /gz { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 perl 'sub { |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 my $r = shift; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 $r->header_out("Content-Encoding", "gzip"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 $r->send_http_header("text/plain"); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 return OK if $r->header_only; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 use IO::Compress::Gzip; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 my $in = "TEST"; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 my $out; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 IO::Compress::Gzip::gzip(\\$in => \\$out); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 $r->print($out); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 return OK; |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 }'; |
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 EOF |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 $t->run(); |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 |
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 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
|
81 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
|
82 |
4bf7a819358c
Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 ############################################################################### |