From 74110bbab1054426256c602088a547aae61f6fd9 Mon Sep 17 00:00:00 2001 From: l37366 Date: Wed, 22 Feb 2012 11:45:25 +0800 Subject: [PATCH 1/8] add support for cache_file and cache_file_like --- lib/Test/Nginx/Socket.pm | 64 ++++++++++++++++++++++++++++++++++++++++ lib/Test/Nginx/Util.pm | 40 +++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index a2669a16..f5fb543b 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -34,6 +34,9 @@ use Test::Nginx::Util qw( $RunTestHelper $RepeatEach error_log_data + cache_file_data + cache_file_like_data + parse_cache_files worker_connections master_process_enabled config_preamble @@ -526,6 +529,7 @@ again: } check_error_log($block, $res, $dry_run, $req_idx, $need_array); + check_cache_file($block, $res, $dry_run, $req_idx, $need_array); $req_idx++; @@ -718,6 +722,66 @@ sub check_error_log ($$$$$) { } +sub check_cache_file ($$$$$) { + my ($block, $res, $dry_run, $req_idx, $need_array) = @_; + my $name = $block->name; + my $lines; + + if (defined $block->cache_file) { + my $pats = parse_cache_files($block->cache_file); + + for my $pat (@$pats) { + if (defined $pat) { + my $lines = cache_file_data(@$pat[0]); + if ($lines eq @$pat[1]) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + pass("$name - content \"@$pat[1]\" matches file \"@$pat[0]\""); + } + undef $pat; + } + } + } + for my $pat (@$pats) { + if (defined $pat) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + fail("$name - content \"@$pat[1]\" not matches file \"@$pat[0]\""); + } + } + } + } + + if (defined $block->cache_file_like) { + my $pats = parse_cache_files($block->cache_file_like); + my %pass; + + for my $pat (@$pats) { + if (defined $pat) { + my $lines = cache_file_like_data(@$pat[0]); + for my $line (@$lines) { + my $val = @$pat[1]; + if ($line =~ /$val/) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + pass("$name - content \"@$pat[1]\" exists in file \"@$pat[0]\""); + } + undef $pat; + } + } + } + } + for my $pat (@$pats) { + if (defined $pat) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + fail("$name - content \"@$pat[1]\" not exists in file \"@$pat[0]\""); + } + } + } + } +} + sub fmt_str ($) { my $str = shift; chomp $str; diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index e9b6739c..f185431e 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -130,6 +130,9 @@ sub master_process_enabled (@) { our @EXPORT_OK = qw( error_log_data + cache_file_data + cache_file_like_data + parse_cache_files setup_server_root write_config_file get_canon_version @@ -213,6 +216,43 @@ sub error_log_data () { return \@lines; } +sub cache_file_data ($) { + my ($cache_file) = @_; + open my $in, $cache_file or + return undef; + my $lines = <$in>; + close $in; + return $lines; +} + +sub cache_file_like_data ($) { + my ($cache_file) = @_; + open my $in, $cache_file or + return undef; + my @lines = <$in>; + close $in; + return \@lines; +} + +sub parse_cache_files ($) { + my $s = shift; + my @headers; + my @lines; + open my $in, '<', \$s; + while (<$in>) { + s/^\s+|\s+$//g; + my $neg = ($_ =~ s/^!\s*//); + if (!$neg) { + my ($key, $val) = split /\s*:\s*/, $_, 2; + @headers = ($key, $val); + push @lines, [ @headers ]; + #warn "neg: $key $val"; + } + } + close $in; + return \@lines; +} + sub run_tests () { $NginxVersion = get_nginx_version(); From 4e32f3b4fea4182e004cda79ab4fcc4beac7fb2c Mon Sep 17 00:00:00 2001 From: l37366 Date: Thu, 23 Feb 2012 10:05:13 +0800 Subject: [PATCH 2/8] add docs --- lib/Test/Nginx/Socket.pm | 56 ++++++++++++++++++++++++++++++++++++++-- lib/Test/Nginx/Util.pm | 2 +- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index f5fb543b..de44adf3 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -754,14 +754,13 @@ sub check_cache_file ($$$$$) { if (defined $block->cache_file_like) { my $pats = parse_cache_files($block->cache_file_like); - my %pass; for my $pat (@$pats) { if (defined $pat) { my $lines = cache_file_like_data(@$pat[0]); for my $line (@$lines) { my $val = @$pat[1]; - if ($line =~ /$val/) { + if ($line =~ /$val/ || $line =~ /\Q$val\E/) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; pass("$name - content \"@$pat[1]\" exists in file \"@$pat[0]\""); @@ -1696,6 +1695,59 @@ Just like the C<--- error_log> section, one can also specify multiple patterns: Then if any line in F contains the string C<"abc"> or match the Perl regex C, then the test will fail. +=head2 cache_file + +Checks if content of the file is equal to specified string. First section seperated by colon is file name and the second section is match string. + + --- cache_file + /tmp/cache_file: abcd + +For example, + + === TEST 1: write to file + --- config + location /write/to/file { + content_by_lua ' + io.output("/tmp/cache_file",rw); + io.write("abcd"); + io.flush(); + io.close(); + '; + } + --- request + GET /write/to/file + --- error_code: 200 + --- cache_file + /tmp/cache_file: abcd + /tmp/cache_file: abc + +Then content of the F is "abcd", first case should be passed and second case failed. + +=head2 cache_file_like + +Checks if specified pattern matches one line of the file. First section seperated by colon is file name and the second section is match pattern. + +For example, + + === TEST 1: write to file + --- config + location /write/to/file { + content_by_lua ' + io.output("/tmp/cache_file",rw); + io.write("abcd"); + io.flush(); + io.close(); + '; + } + --- request + GET /write/to/file + --- error_code: 200 + --- cache_file_like + /tmp/cache_file: abcde + /tmp/cache_file: ^abc + +Then content of the F is "abcd", first case should be failed and second case passed. + =head2 raw_request The exact request to send to nginx. This is useful when you want to test diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index f185431e..33279fee 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -220,7 +220,7 @@ sub cache_file_data ($) { my ($cache_file) = @_; open my $in, $cache_file or return undef; - my $lines = <$in>; + my $lines = do { local $/; <$in>; }; close $in; return $lines; } From 91cf093e10465e8336ce274cd0782ca164b83727 Mon Sep 17 00:00:00 2001 From: l37366 Date: Thu, 23 Feb 2012 11:12:48 +0800 Subject: [PATCH 3/8] mofify to --- lib/Test/Nginx/Socket.pm | 104 +++++++++++++++++++++++++++++---------- lib/Test/Nginx/Util.pm | 20 ++++---- 2 files changed, 89 insertions(+), 35 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index de44adf3..4e660662 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -34,9 +34,9 @@ use Test::Nginx::Util qw( $RunTestHelper $RepeatEach error_log_data - cache_file_data - cache_file_like_data - parse_cache_files + file_data + file_like_data + parse_files worker_connections master_process_enabled config_preamble @@ -529,7 +529,7 @@ again: } check_error_log($block, $res, $dry_run, $req_idx, $need_array); - check_cache_file($block, $res, $dry_run, $req_idx, $need_array); + check_files($block, $res, $dry_run, $req_idx, $need_array); $req_idx++; @@ -722,17 +722,17 @@ sub check_error_log ($$$$$) { } -sub check_cache_file ($$$$$) { +sub check_files ($$$$$) { my ($block, $res, $dry_run, $req_idx, $need_array) = @_; my $name = $block->name; my $lines; - if (defined $block->cache_file) { - my $pats = parse_cache_files($block->cache_file); + if (defined $block->files) { + my $pats = parse_files($block->files); for my $pat (@$pats) { if (defined $pat) { - my $lines = cache_file_data(@$pat[0]); + my $lines = file_data(@$pat[0]); if ($lines eq @$pat[1]) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; @@ -752,12 +752,12 @@ sub check_cache_file ($$$$$) { } } - if (defined $block->cache_file_like) { - my $pats = parse_cache_files($block->cache_file_like); + if (defined $block->files_like) { + my $pats = parse_files($block->files_like); for my $pat (@$pats) { if (defined $pat) { - my $lines = cache_file_like_data(@$pat[0]); + my $lines = file_like_data(@$pat[0]); for my $line (@$lines) { my $val = @$pat[1]; if ($line =~ /$val/ || $line =~ /\Q$val\E/) { @@ -779,6 +779,34 @@ sub check_cache_file ($$$$$) { } } } + + if (defined $block->files_not_like) { + my $pats = parse_files($block->files_not_like); + + for my $pat (@$pats) { + if (defined $pat) { + my $lines = file_like_data(@$pat[0]); + for my $line (@$lines) { + my $val = @$pat[1]; + if ($line =~ /$val/ || $line =~ /\Q$val\E/) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + fail("$name - content \"@$pat[1]\" exists in file \"@$pat[0]\""); + } + undef $pat; + } + } + } + } + for my $pat (@$pats) { + if (defined $pat) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + pass("$name - content \"@$pat[1]\" not exists in file \"@$pat[0]\""); + } + } + } + } } sub fmt_str ($) { @@ -1695,12 +1723,12 @@ Just like the C<--- error_log> section, one can also specify multiple patterns: Then if any line in F contains the string C<"abc"> or match the Perl regex C, then the test will fail. -=head2 cache_file +=head2 files Checks if content of the file is equal to specified string. First section seperated by colon is file name and the second section is match string. - --- cache_file - /tmp/cache_file: abcd + --- files + /tmp/file: abcd For example, @@ -1708,7 +1736,7 @@ For example, --- config location /write/to/file { content_by_lua ' - io.output("/tmp/cache_file",rw); + io.output("/tmp/file",rw); io.write("abcd"); io.flush(); io.close(); @@ -1717,13 +1745,13 @@ For example, --- request GET /write/to/file --- error_code: 200 - --- cache_file - /tmp/cache_file: abcd - /tmp/cache_file: abc + --- files + /tmp/file: abcd + /tmp/file: abc -Then content of the F is "abcd", first case should be passed and second case failed. +Then content of the F is "abcd", first case should be passed and second case failed. -=head2 cache_file_like +=head2 files_like Checks if specified pattern matches one line of the file. First section seperated by colon is file name and the second section is match pattern. @@ -1733,7 +1761,33 @@ For example, --- config location /write/to/file { content_by_lua ' - io.output("/tmp/cache_file",rw); + io.output("/tmp/file",rw); + io.write("abcd"); + io.flush(); + io.close(); + '; + } + --- request + GET /write/to/file + --- error_code: 200 + --- file_likes + /tmp/file: abcde + /tmp/file: ^abc + +Then content of the F is "abcd", first case should be failed and second case passed. + +=head2 files_not_like + +Likes C<--- file_like> section, but does the opposite test, i.e., +checks if specified pattern matches none line of the file. First section seperated by colon is file name and the second section is match pattern. + +For example, + + === TEST 1: write to file + --- config + location /write/to/file { + content_by_lua ' + io.output("/tmp/file",rw); io.write("abcd"); io.flush(); io.close(); @@ -1742,11 +1796,11 @@ For example, --- request GET /write/to/file --- error_code: 200 - --- cache_file_like - /tmp/cache_file: abcde - /tmp/cache_file: ^abc + --- files_not_like + /tmp/file: abc + /tmp/file: ^bc -Then content of the F is "abcd", first case should be failed and second case passed. +Then content of the F is "abcd", first case should be failed and second case passed. =head2 raw_request diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index 33279fee..b59a58c8 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -130,9 +130,9 @@ sub master_process_enabled (@) { our @EXPORT_OK = qw( error_log_data - cache_file_data - cache_file_like_data - parse_cache_files + file_data + file_like_data + parse_files setup_server_root write_config_file get_canon_version @@ -216,25 +216,25 @@ sub error_log_data () { return \@lines; } -sub cache_file_data ($) { - my ($cache_file) = @_; - open my $in, $cache_file or +sub file_data ($) { + my ($file) = @_; + open my $in, $file or return undef; my $lines = do { local $/; <$in>; }; close $in; return $lines; } -sub cache_file_like_data ($) { - my ($cache_file) = @_; - open my $in, $cache_file or +sub file_like_data ($) { + my ($file) = @_; + open my $in, $file or return undef; my @lines = <$in>; close $in; return \@lines; } -sub parse_cache_files ($) { +sub parse_files ($) { my $s = shift; my @headers; my @lines; From 9746359bc22633c363b3ea3bc94d8f52947b8499 Mon Sep 17 00:00:00 2001 From: l37366 Date: Thu, 23 Feb 2012 11:13:33 +0800 Subject: [PATCH 4/8] fix docs --- lib/Test/Nginx/Socket.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index 4e660662..75c91113 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -1770,7 +1770,7 @@ For example, --- request GET /write/to/file --- error_code: 200 - --- file_likes + --- files_like /tmp/file: abcde /tmp/file: ^abc From 787fd917f604e13f6b6bfb954b0629d0f13cd2ec Mon Sep 17 00:00:00 2001 From: l37366 Date: Thu, 23 Feb 2012 13:03:11 +0800 Subject: [PATCH 5/8] add files_exist,files_not_exist,pre_remove_files --- lib/Test/Nginx/Socket.pm | 100 +++++++++++++++++++++++++++++++++++++-- lib/Test/Nginx/Util.pm | 26 ++++++++++ 2 files changed, 122 insertions(+), 4 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index 75c91113..eb73db91 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -763,7 +763,7 @@ sub check_files ($$$$$) { if ($line =~ /$val/ || $line =~ /\Q$val\E/) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; - pass("$name - content \"@$pat[1]\" exists in file \"@$pat[0]\""); + pass("$name - files_like: content \"@$pat[1]\" exists in file \"@$pat[0]\""); } undef $pat; } @@ -774,7 +774,7 @@ sub check_files ($$$$$) { if (defined $pat) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; - fail("$name - content \"@$pat[1]\" not exists in file \"@$pat[0]\""); + fail("$name - files_like: content \"@$pat[1]\" not exists in file \"@$pat[0]\""); } } } @@ -791,7 +791,7 @@ sub check_files ($$$$$) { if ($line =~ /$val/ || $line =~ /\Q$val\E/) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; - fail("$name - content \"@$pat[1]\" exists in file \"@$pat[0]\""); + fail("$name - files_not_like: content \"@$pat[1]\" exists in file \"@$pat[0]\""); } undef $pat; } @@ -802,11 +802,72 @@ sub check_files ($$$$$) { if (defined $pat) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; - pass("$name - content \"@$pat[1]\" not exists in file \"@$pat[0]\""); + pass("$name - files_not_like: content \"@$pat[1]\" not exists in file \"@$pat[0]\""); } } } } + + if ($block->files_exist) { + my $files = $block->files_exist; + if (!ref $files) { + chomp $files; + my @lines = split /\n+/, $files; + $files = \@lines; + } else { + my @clone = @$files; + $files = \@clone; + } + + for my $file (@$files) { + if (-e $file) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + pass("$name - files_exist: \"$file\" exists"); + } + undef $file; + } + } + for my $file (@$files) { + if (defined $file) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + fail("$name - files_exist: \"$file\" is not existing"); + } + } + } + } + + if ($block->files_not_exist) { + my $files = $block->files_not_exist; + if (!ref $files) { + chomp $files; + my @lines = split /\n+/, $files; + $files = \@lines; + } else { + my @clone = @$files; + $files = \@clone; + } + + for my $file (@$files) { + if (-e $file) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + fail("$name - files_not_exist: \"$file\" exists"); + } + undef $file; + } + } + for my $file (@$files) { + if (defined $file) { + SKIP: { + skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; + pass("$name - files_not_exist: \"$file\" is not existing"); + } + } + } + } + } sub fmt_str ($) { @@ -1802,6 +1863,37 @@ For example, Then content of the F is "abcd", first case should be failed and second case passed. +=head2 pre_remove_files + +Remove files before start nginx. Both multi lines and eval are supported. For example: + + --- pre_remove_files + /tmp/file + /tmp/file1 + +and: + + --- pre_remove_files eval + ["/tmp/file", "/tmp/file1"] + +=head2 files_exist + +Check if specified files exist. + + --- files_exist + /tmp/file + /tmp/file1 + +And "eval" is also supported. + + --- files_exist eval + ["/tmp/file2", "/tmp/file3"] + + +=head2 files_not_exist + +Likes C<--- files_exist> section, but does the opposite test. + =head2 raw_request The exact request to send to nginx. This is useful when you want to test diff --git a/lib/Test/Nginx/Util.pm b/lib/Test/Nginx/Util.pm index b59a58c8..e9899a4a 100644 --- a/lib/Test/Nginx/Util.pm +++ b/lib/Test/Nginx/Util.pm @@ -253,6 +253,31 @@ sub parse_files ($) { return \@lines; } +sub pre_remove_files ($) { + my $block = shift; + + my $name = $block->name; + + if ($block->pre_remove_files) { + my $files = $block->pre_remove_files; + if (!ref $files) { + chomp $files; + my @lines = split /\n+/, $files; + $files = \@lines; + } else { + my @clone = @$files; + $files = \@clone; + } + + for my $file (@$files) { + if (-e $file) { + unlink $file or die "unlink $file failed\n"; + } + } + + } +} + sub run_tests () { $NginxVersion = get_nginx_version(); @@ -767,6 +792,7 @@ start_nginx: #warn "*** Restarting the nginx server...\n"; setup_server_root(); write_user_files($block); + pre_remove_files($block); write_config_file($config, $block->http_config, $block->main_config); #warn "nginx binary: $NginxBinary"; if ( ! can_run($NginxBinary) ) { From a2ba8f15338a760248f370719b8d1ddd6146eb1d Mon Sep 17 00:00:00 2001 From: l37366 Date: Thu, 23 Feb 2012 15:27:07 +0800 Subject: [PATCH 6/8] modify usage of "files" --- lib/Test/Nginx/Socket.pm | 75 ++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index eb73db91..23ba608c 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -728,28 +728,63 @@ sub check_files ($$$$$) { my $lines; if (defined $block->files) { - my $pats = parse_files($block->files); + my $raw = $block->files; + + open my $in, '<', \$raw; + + my @files; + my ($fname, $body, $chop); + while (<$in>) { + if (/>>> (\S+)\s?(\S*)/) { + if ($fname) { + push @files, [$fname, $body, $chop]; + } + $fname = $1; + if ($2 eq "chop") { + $chop = 1; + } else { + $chop = 0; + } + undef $body; + } else { + $body .= $_; + } + } + if ($fname) { + push @files, [$fname, $body, $chop]; + } - for my $pat (@$pats) { - if (defined $pat) { - my $lines = file_data(@$pat[0]); - if ($lines eq @$pat[1]) { + for my $file (@files) { + my ($fname, $body, $chop) = @$file; + + if (!defined $body) { + $body = ''; + } + if (defined $file) { + my $lines = file_data($fname); + if ($chop == 1) { + chop $body; + } + if ($lines eq $body) { SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; - pass("$name - content \"@$pat[1]\" matches file \"@$pat[0]\""); + pass("$name - content \"$body\" matches file \"$fname\""); } - undef $pat; + undef $file; } } } - for my $pat (@$pats) { - if (defined $pat) { + + for my $file (@files) { + if (defined $file) { + my ($fname, $body, $chop) = @$file; SKIP: { skip "$name - tests skipped due to the lack of directive $dry_run", 1 if $dry_run; - fail("$name - content \"@$pat[1]\" not matches file \"@$pat[0]\""); + fail("$name - content \"$body\" not matches file \"$fname\""); } } } + } if (defined $block->files_like) { @@ -1786,19 +1821,19 @@ Then if any line in F contains the string C<"abc"> or match the Perl =head2 files -Checks if content of the file is equal to specified string. First section seperated by colon is file name and the second section is match string. - - --- files - /tmp/file: abcd +Checks if content of the file is equal to specified string. Usage most likes user_files, additional directive "chop" is added to remove unnecessary "\n" for some files. For example, - === TEST 1: write to file + === TEST 0: write to file --- config location /write/to/file { content_by_lua ' io.output("/tmp/file",rw); - io.write("abcd"); + io.write("hello"); + io.flush(); + io.output("/tmp/file1",rw); + io.write("hello\\nworld\\n"); io.flush(); io.close(); '; @@ -1807,8 +1842,12 @@ For example, GET /write/to/file --- error_code: 200 --- files - /tmp/file: abcd - /tmp/file: abc + >>> /tmp/file chop + hello + >>> /tmp/file1 + hello + world + Then content of the F is "abcd", first case should be passed and second case failed. From 8f6da3b9fd21a88e67eb47e1991df2be66be2c61 Mon Sep 17 00:00:00 2001 From: l37366 Date: Thu, 23 Feb 2012 16:24:07 +0800 Subject: [PATCH 7/8] modify names to output_files etc --- lib/Test/Nginx/Socket.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index 23ba608c..3e427ab1 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -727,8 +727,8 @@ sub check_files ($$$$$) { my $name = $block->name; my $lines; - if (defined $block->files) { - my $raw = $block->files; + if (defined $block->output_files) { + my $raw = $block->output_files; open my $in, '<', \$raw; @@ -787,8 +787,8 @@ sub check_files ($$$$$) { } - if (defined $block->files_like) { - my $pats = parse_files($block->files_like); + if (defined $block->output_files_like) { + my $pats = parse_files($block->output_files_like); for my $pat (@$pats) { if (defined $pat) { @@ -815,8 +815,8 @@ sub check_files ($$$$$) { } } - if (defined $block->files_not_like) { - my $pats = parse_files($block->files_not_like); + if (defined $block->output_files_unlike) { + my $pats = parse_files($block->output_files_unlike); for my $pat (@$pats) { if (defined $pat) { @@ -1819,7 +1819,7 @@ Just like the C<--- error_log> section, one can also specify multiple patterns: Then if any line in F contains the string C<"abc"> or match the Perl regex C, then the test will fail. -=head2 files +=head2 output_files Checks if content of the file is equal to specified string. Usage most likes user_files, additional directive "chop" is added to remove unnecessary "\n" for some files. @@ -1841,7 +1841,7 @@ For example, --- request GET /write/to/file --- error_code: 200 - --- files + --- output_files >>> /tmp/file chop hello >>> /tmp/file1 @@ -1851,7 +1851,7 @@ For example, Then content of the F is "abcd", first case should be passed and second case failed. -=head2 files_like +=head2 output_files_like Checks if specified pattern matches one line of the file. First section seperated by colon is file name and the second section is match pattern. @@ -1870,15 +1870,15 @@ For example, --- request GET /write/to/file --- error_code: 200 - --- files_like + --- output_files_like /tmp/file: abcde /tmp/file: ^abc Then content of the F is "abcd", first case should be failed and second case passed. -=head2 files_not_like +=head2 output_files_unlike -Likes C<--- file_like> section, but does the opposite test, i.e., +Likes C<--- output_files_like> section, but does the opposite test, i.e., checks if specified pattern matches none line of the file. First section seperated by colon is file name and the second section is match pattern. For example, @@ -1896,7 +1896,7 @@ For example, --- request GET /write/to/file --- error_code: 200 - --- files_not_like + --- output_files_unlike /tmp/file: abc /tmp/file: ^bc From c911cf358275f70122004a071b25929bbc9ceb9d Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 18 May 2012 15:40:35 +0800 Subject: [PATCH 8/8] docs add timeout --- lib/Test/Nginx/Socket.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Test/Nginx/Socket.pm b/lib/Test/Nginx/Socket.pm index b64b37c4..b57c2b14 100644 --- a/lib/Test/Nginx/Socket.pm +++ b/lib/Test/Nginx/Socket.pm @@ -1778,6 +1778,12 @@ test) is listening to: As usual, if the test is made of multiple requests, then raw_response_headers_like B be an array. +=head2 timeout + +Specifys the timeout value for test case running, default to 2(sec). + + --- timeout: 50 + =head2 error_code The expected value of the HTTP response code. If not set, this is assumed