# HG changeset patch # User Maxim Dounin # Date 1261436341 -10800 # Node ID 4bf7a819358cd2ad53f40cc4562a38f11964f068 # Parent f2b8d86438eee5a41c71e4d15bc186cde7e551a4 Tests: add some embedded perl tests. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -66,6 +66,7 @@ sub has_module($) { my %regex = ( mail => '--with-mail', flv => '--with-http_flv_module', + perl => '--with-http_perl_module', rewrite => '(?s)^(?!.*--without-http_rewrite_module)', gzip => '(?s)^(?!.*--without-http_gzip_module)', cache => '(?s)^(?!.*--without-http-cache)', diff --git a/perl-gzip.t b/perl-gzip.t new file mode 100644 --- /dev/null +++ b/perl-gzip.t @@ -0,0 +1,90 @@ +#!/usr/bin/perl + +# (C) Maxim Dounin + +# Tests for embedded perl module. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx qw/ :DEFAULT :gzip /; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +eval { require IO::Compress::Gzip; }; +Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@; + +my $t = Test::Nginx->new()->has('perl')->has('gzip')->plan(2) + ->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +master_process off; +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + server { + listen 127.0.0.1:8080; + server_name localhost; + + gzip on; + gzip_types text/plain; + + location / { + perl 'sub { + my $r = shift; + $r->send_http_header("text/plain"); + return OK if $r->header_only; + $r->print("TEST"); + return OK; + }'; + } + + location /gz { + perl 'sub { + my $r = shift; + $r->header_out("Content-Encoding", "gzip"); + $r->send_http_header("text/plain"); + return OK if $r->header_only; + use IO::Compress::Gzip; + my $in = "TEST"; + my $out; + IO::Compress::Gzip::gzip(\\$in => \\$out); + $r->print($out); + return OK; + }'; + } + } +} + +EOF + +$t->run(); + +############################################################################### + +http_gzip_like(http_gzip_request('/'), qr/TEST/, 'perl response gzipped'); + +TODO: { +local $TODO = 'patch pending'; + +http_gzip_like(http_gzip_request('/gz'), qr/TEST/, 'not doublegzipped'); + +} + +############################################################################### diff --git a/perl.t b/perl.t new file mode 100644 --- /dev/null +++ b/perl.t @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +# (C) Maxim Dounin + +# Tests for embedded perl module. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +my $t = Test::Nginx->new()->has('perl')->has('rewrite')->plan(1) + ->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +master_process off; +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + server { + listen 127.0.0.1:8080; + server_name localhost; + + location / { + set $testvar "TEST"; + perl 'sub { + use warnings; + use strict; + + my $r = shift; + + $r->send_http_header("text/plain"); + + return OK if $r->header_only; + + my $v = $r->variable("testvar"); + + $r->print("$v"); + + return OK; + }'; + } + } +} + +EOF + +$t->run(); + +############################################################################### + +like(http_get('/'), qr/TEST/, 'perl response'); + +###############################################################################