# HG changeset patch # User Maxim Dounin # Date 1221260221 -14400 # Node ID c6c36d7a4d90e72f0d10646fc4198e168467a848 # Parent d4b74207a627df0f3f5739a74de6b1e452fce055 Tests: support config embedded in test itself. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -24,6 +24,14 @@ use Socket qw/ CRLF /; sub new { my $self = {}; bless $self; + + $self->{_testdir} = tempdir( + 'nginx-test-XXXXXXXXXX', + TMPDIR => 1, + CLEANUP => not $ENV{LEAVE} + ) + or die "Can't create temp directory: $!\n"; + return $self; } @@ -32,19 +40,15 @@ sub DESTROY { $self->stop(); } -# Create temp directory and run nginx instance. - sub run { my ($self, $conf) = @_; - my $testdir = tempdir('nginx-test-XXXXXXXXXX', TMPDIR => 1, - CLEANUP => not $ENV{LEAVE}) - or die "Can't create temp directory: $!\n"; + my $testdir = $self->{_testdir}; - $self->{_testdir} = $testdir; - - system("cat $conf | sed 's!%%TESTDIR%%!$testdir!g' " - . "> $testdir/nginx.conf"); + if (defined $conf) { + my $c = `cat $conf`; + $self->write_file_expand('nginx.conf', $c); + } my $pid = fork(); die "Unable to fork(): $!\n" unless defined $pid; @@ -63,7 +67,7 @@ sub run { return $self; } -sub stop { +sub stop() { my ($self) = @_; # terminate nginx by SIGTERM @@ -73,7 +77,7 @@ sub stop { return $self; } -sub write_file { +sub write_file($$) { my ($self, $name, $content) = @_; open F, '>' . $self->{_testdir} . '/' . $name @@ -84,6 +88,14 @@ sub write_file { return $self; } +sub write_file_expand($$) { + my ($self, $name, $content) = @_; + + $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms; + + return $self->write_file($name, $content); +} + ############################################################################### sub log_out { diff --git a/ssi-include-big.conf b/ssi-include-big.conf deleted file mode 100644 --- a/ssi-include-big.conf +++ /dev/null @@ -1,33 +0,0 @@ -# Config for ssi-include-big.t test. - -worker_processes 1; - -master_process off; -daemon off; - -events { - worker_connections 1024; -} - -http { - access_log off; - root %%TESTDIR%%; - - output_buffers 2 512; - ssi on; - gzip on; - gzip_http_version 1.0; - - - server { - listen localhost:8080; - server_name localhost; - - location /proxy/ { - proxy_pass http://localhost:8080/local/; - } - location = /local/blah { - return 204; - } - } -} diff --git a/ssi-include-big.t b/ssi-include-big.t --- a/ssi-include-big.t +++ b/ssi-include-big.t @@ -21,7 +21,39 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->run('ssi-include-big.conf'); +my $t = Test::Nginx->new(); + +$t->write_file_expand('nginx.conf', <<'EOF'); + +master_process off; +daemon off; + +events { + worker_connections 1024; +} + +http { + access_log off; + root %%TESTDIR%%; + + output_buffers 2 512; + ssi on; + gzip on; + + server { + listen localhost:8080; + server_name localhost; + + location /proxy/ { + proxy_pass http://localhost:8080/local/; + } + location = /local/blah { + return 204; + } + } +} + +EOF $t->write_file('c1.html', 'X' x 1023); $t->write_file('c2.html', 'X' x 1024); @@ -33,6 +65,8 @@ my $t = Test::Nginx->new()->run('ssi-inc $t->write_file('test3.html', '' . "\n" . ''); +$t->run(); + ############################################################################### my $t1 = http_gzip_request('/test1.html'); @@ -49,7 +83,7 @@ ok(defined $t3, 'big included file (more sub http_gzip_request { my ($url) = @_; my $r = http(<