Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated Test::Nginx.

  • Loading branch information...
commit 442f8663818bd1dd0f9ec1f1b807e2099248c78c 1 parent 8447e58
@agentzh agentzh authored
View
66 test/lib/Test/Nginx/LWP.pm
@@ -51,7 +51,7 @@ sub no_long_string () {
$NoLongString = 1;
}
-sub run_test_helper ($);
+sub run_test_helper ($$);
$RunTestHelper = \&run_test_helper;
@@ -96,8 +96,8 @@ sub chunk_it ($$$) {
}
}
-sub run_test_helper ($) {
- my ($block) = @_;
+sub run_test_helper ($$) {
+ my ($block, $dry_run) = @_;
my $request = $block->request;
@@ -162,14 +162,23 @@ sub run_test_helper ($) {
#warn "req: ", $req->as_string, "\n";
#warn "DONE!!!!!!!!!!!!!!!!!!!!";
- my $res = $UserAgent->request($req);
+ my $res = HTTP::Response->new;
+ unless ($dry_run) {
+ $res = $UserAgent->request($req);
+ }
#warn "res returned!!!";
- if (defined $block->error_code) {
- is($res->code, $block->error_code, "$name - status code ok");
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
} else {
- is($res->code, 200, "$name - status code ok");
+ if (defined $block->error_code) {
+ is($res->code, $block->error_code, "$name - status code ok");
+ } else {
+ is($res->code, 200, "$name - status code ok");
+ }
}
if (defined $block->response_headers) {
@@ -179,8 +188,14 @@ sub run_test_helper ($) {
if (!defined $expected_val) {
$expected_val = '';
}
- is $expected_val, $val,
- "$name - header $key ok";
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ is $expected_val, $val,
+ "$name - header $key ok";
+ }
}
} elsif (defined $block->response_headers_like) {
my $headers = parse_headers($block->response_headers_like);
@@ -189,8 +204,14 @@ sub run_test_helper ($) {
if (!defined $expected_val) {
$expected_val = '';
}
- like $expected_val, qr/^$val$/,
- "$name - header $key like ok";
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ like $expected_val, qr/^$val$/,
+ "$name - header $key like ok";
+ }
}
}
@@ -206,12 +227,18 @@ sub run_test_helper ($) {
$expected =~ s/\$ServerPortForClient\b/$ServerPortForClient/g;
#warn show_all_chars($content);
- if ($NoLongString) {
- is($content, $expected, "$name - response_body - response is expected");
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
} else {
- is_string($content, $expected, "$name - response_body - response is expected");
+ if ($NoLongString) {
+ is($content, $expected, "$name - response_body - response is expected");
+ } else {
+ is_string($content, $expected, "$name - response_body - response is expected");
+ }
+ #is($content, $expected, "$name - response_body - response is expected");
}
- #is($content, $expected, "$name - response_body - response is expected");
} elsif (defined $block->response_body_like) {
my $content = $res->content;
@@ -223,7 +250,14 @@ sub run_test_helper ($) {
$expected_pat =~ s/\$ServerPort\b/$ServerPort/g;
$expected_pat =~ s/\$ServerPortForClient\b/$ServerPortForClient/g;
my $summary = trim($content);
- like($content, qr/$expected_pat/s, "$name - response_body_like - response is expected ($summary)");
+
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ like($content, qr/$expected_pat/s, "$name - response_body_like - response is expected ($summary)");
+ }
}
}
View
77 test/lib/Test/Nginx/Socket.pm
@@ -67,7 +67,7 @@ our @EXPORT = qw( plan run_tests run_test
sub send_request ($$$$);
-sub run_test_helper ($);
+sub run_test_helper ($$);
sub error_event_handler ($);
sub read_event_handler ($);
@@ -126,8 +126,8 @@ sub parse_request ($$) {
};
}
-sub run_test_helper ($) {
- my $block = shift;
+sub run_test_helper ($$) {
+ my ($block, $dry_run) = @_;
my $name = $block->name;
@@ -225,8 +225,14 @@ $parsed_req->{content}";
$timeout = $Timeout;
}
- my $raw_resp = send_request($req, $block->raw_request_middle_delay,
- $timeout, $block->name);
+ my $raw_resp;
+
+ if ($dry_run) {
+ $raw_resp = "200 OK HTTP/1.0\r\nContent-Length: 0\r\n\r\n";
+ } else {
+ $raw_resp = send_request($req, $block->raw_request_middle_delay,
+ $timeout, $block->name);
+ }
#warn "raw resonse: [$raw_resp]\n";
@@ -285,10 +291,16 @@ $parsed_req->{content}";
$res->content($decoded);
}
- if (defined $block->error_code) {
- is($res->code || '', $block->error_code, "$name - status code ok");
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
} else {
- is($res->code || '', 200, "$name - status code ok");
+ if (defined $block->error_code) {
+ is($res->code || '', $block->error_code, "$name - status code ok");
+ } else {
+ is($res->code || '', 200, "$name - status code ok");
+ }
}
if (defined $block->response_headers) {
@@ -296,7 +308,13 @@ $parsed_req->{content}";
while (my ($key, $val) = each %$headers) {
if (!defined $val) {
#warn "HIT";
- unlike $raw_headers, qr/^\s*\Q$key\E\s*:/ms, "$name - header $key not present in the raw headers";
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ unlike $raw_headers, qr/^\s*\Q$key\E\s*:/ms, "$name - header $key not present in the raw headers";
+ }
next;
}
@@ -305,8 +323,14 @@ $parsed_req->{content}";
$actual_val = '';
}
- is $actual_val, $val,
- "$name - header $key ok";
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ is $actual_val, $val,
+ "$name - header $key ok";
+ }
}
} elsif (defined $block->response_headers_like) {
my $headers = parse_headers($block->response_headers_like);
@@ -315,8 +339,14 @@ $parsed_req->{content}";
if (!defined $expected_val) {
$expected_val = '';
}
- like $expected_val, qr/^$val$/,
- "$name - header $key like ok";
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ like $expected_val, qr/^$val$/,
+ "$name - header $key like ok";
+ }
}
}
@@ -347,10 +377,16 @@ $parsed_req->{content}";
#warn show_all_chars($content);
#warn "no long string: $NoLongString";
- if ($NoLongString) {
- is($content, $expected, "$name - response_body - response is expected");
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
} else {
- is_string($content, $expected, "$name - response_body - response is expected");
+ if ($NoLongString) {
+ is($content, $expected, "$name - response_body - response is expected");
+ } else {
+ is_string($content, $expected, "$name - response_body - response is expected");
+ }
}
} elsif (defined $block->response_body_like) {
@@ -363,7 +399,14 @@ $parsed_req->{content}";
$expected_pat =~ s/\$ServerPort\b/$ServerPort/g;
$expected_pat =~ s/\$ServerPortForClient\b/$ServerPortForClient/g;
my $summary = trim($content);
- like($content, qr/$expected_pat/s, "$name - response_body_like - response is expected ($summary)");
+
+ if ($dry_run) {
+ SKIP: {
+ Test::More::skip("$name - tests skipped due to the lack of directive $dry_run", 1);
+ }
+ } else {
+ like($content, qr/$expected_pat/s, "$name - response_body_like - response is expected ($summary)");
+ }
}
}
View
36 test/lib/Test/Nginx/Util.pm
@@ -431,6 +431,25 @@ sub expand_env_in_config ($) {
$config;
}
+sub check_if_missing_directives () {
+ open my $in, $ErrLogFile or
+ bail_out "check_if_missing_directives: Cannot open $ErrLogFile for reading: $!\n";
+
+ while (<$in>) {
+ #warn $_;
+ if (/\[emerg\] \S+?: unknown directive "([^"]+)"/) {
+ #warn "MATCHED!!! $1";
+ return $1;
+ }
+ }
+
+ close $in;
+
+ #warn "NOT MATCHED!!!";
+
+ return 0;
+}
+
sub run_test ($) {
my $block = shift;
my $name = $block->name;
@@ -439,6 +458,8 @@ sub run_test ($) {
$config = expand_env_in_config($config);
+ my $dry_run = 0;
+
if (!defined $config) {
bail_out("$name - No '--- config' section specified");
#$config = $PrevConfig;
@@ -628,7 +649,14 @@ start_nginx:
}
} else {
if (system($cmd) != 0) {
- bail_out("$name - Cannot start nginx using command \"$cmd\".");
+ if ($ENV{TEST_NGINX_IGNORE_MISSING_DIRECTIVES} and
+ my $directive = check_if_missing_directives())
+ {
+ $dry_run = $directive;
+
+ } else {
+ bail_out("$name - Cannot start nginx using command \"$cmd\".");
+ }
}
}
@@ -649,16 +677,16 @@ start_nginx:
SKIP: {
Test::More::skip("$name - $skip_reason", $tests_to_skip);
- $RunTestHelper->($block);
+ $RunTestHelper->($block, $dry_run);
}
} elsif ($should_todo) {
TODO: {
local $TODO = "$name - $todo_reason";
- $RunTestHelper->($block);
+ $RunTestHelper->($block, $dry_run);
}
} else {
- $RunTestHelper->($block);
+ $RunTestHelper->($block, $dry_run);
}
}
View
2  test/t/phase.t
@@ -1,7 +1,7 @@
# vi:filetype=perl
use lib 'lib';
-use Test::Nginx::LWP;
+use Test::Nginx::Socket;
plan tests => 3;
Please sign in to comment.
Something went wrong with that request. Please try again.