Permalink
Browse files

CPAN Version 0.03.

- Fixed test failures in t/analyze_response.t
- Added a few tests more in t/analyze_response.t
  • Loading branch information...
1 parent dd16521 commit 0b1ad5211283a84094f2b918718183704370d3d2 @cosimo committed Jan 16, 2010
Showing with 38 additions and 8 deletions.
  1. +6 −2 Changes
  2. +5 −3 lib/Test/Varnish.pm
  3. +27 −3 t/analyze-response.t
View
@@ -1,9 +1,13 @@
Revision history for Test-Varnish
-0.02 2010/01/14 22:00
+0.03 2010/01/16
+ This should fix all test failures.
+ All tests in t/analyze-response.t were failing. Test plan was output after a use_ok().
+
+0.02 2010/01/14
Completed documentation, and fixed a test script glitch that
caused test failure reports on Windows.
-0.01 2010/01/13 21:00
+0.01 2010/01/13
First version, released on an unsuspecting world.
View
@@ -1,6 +1,6 @@
package Test::Varnish;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
use warnings;
use strict;
@@ -38,7 +38,7 @@ sub analyze_response {
# "X-Varnish: 2131920313 1299858343" means cached
# "X-Varnish: 2039442137" means not cached
- if (defined $main_header && $main_header =~ m{^ \s* \S+ \s+ \S+ \s* $}mx) {
+ if (defined $main_header && $main_header =~ m{^ \s* \d+ \s+ \d+ \s* $}mx) {
$cached = 1;
}
@@ -173,8 +173,10 @@ sub request {
sub _response_sets_cookies {
my ($res) = @_;
+
my $cookie_header = $res->header("Set-Cookie");
#diag("cookie_header: " . ($cookie_header || ""));
+
return defined $cookie_header && $cookie_header ne q{}
? 1
: 0;
@@ -220,7 +222,7 @@ Test::Varnish - Put your Varnish server to the test!
=head1 VERSION
-Version 0.02
+Version 0.03
=head1 SYNOPSIS
View
@@ -6,9 +6,9 @@ use HTTP::Headers;
use HTTP::Response;
use Test::More;
-use_ok('Test::Varnish');
+plan tests => 6;
-plan tests => 4;
+use_ok('Test::Varnish');
my $tv = Test::Varnish->new();
@@ -25,7 +25,7 @@ is(
# Header with two IDs means response was cached
$head = HTTP::Headers->new();
-$head->push_header('X-Varnish', '123456780 123456789');
+$head->push_header('X-Varnish', '123456789 123456780');
$resp = HTTP::Response->new(200, 'OK', $head, '<html/>');
$is_cached = $tv->analyze_response($resp);
@@ -47,3 +47,27 @@ is(
'No varnish header. Can\'t be cached.',
);
+# Undef or empty header also means no Varnish
+$head = HTTP::Headers->new();
+$head->push_header('X-Varnish' => ' ');
+
+$resp = HTTP::Response->new(200, 'OK', $head, '<html/>');
+$is_cached = $tv->analyze_response($resp);
+
+is(
+ $is_cached => 0,
+ 'Invalid Varnish header. Should not be detected as cached.',
+);
+
+$head = HTTP::Headers->new();
+$head->push_header('X-Varnish' => ' abc abc ');
+
+$resp = HTTP::Response->new(200, 'OK', $head, '<html/>');
+$is_cached = $tv->analyze_response($resp);
+
+is(
+ $is_cached => 0,
+ 'Invalid Varnish header. Should not be detected as cached.',
+);
+
+

0 comments on commit 0b1ad52

Please sign in to comment.