summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-06-25 16:27:56 +0200
committerfranck cuny <franck@lumberjaph.net>2009-06-25 16:27:56 +0200
commitc24358060c208915d639ac12d1f39fbbff0c15bc (patch)
treef3f3741fc68dd0cd8ed12cc8fde21e59cb6c7483
parentupdate licence (diff)
downloadmoosex-useragent-c24358060c208915d639ac12d1f39fbbff0c15bc.tar.gz
add tests
-rw-r--r--lib/MooseX/UserAgent/Config.pm2
-rw-r--r--t/tests/Test/MooseX/UserAgent.pm46
2 files changed, 35 insertions, 13 deletions
diff --git a/lib/MooseX/UserAgent/Config.pm b/lib/MooseX/UserAgent/Config.pm
index 89514c8..0b9beb4 100644
--- a/lib/MooseX/UserAgent/Config.pm
+++ b/lib/MooseX/UserAgent/Config.pm
@@ -15,7 +15,7 @@ has 'agent' => (
         my $conf = $self->useragent_conf;
         $ua->agent( $conf->{name} ) if $conf->{name};
         $ua->from( $conf->{mail} )  if $conf->{mail};
-        $ua->max_size( $conf->{max_size} || 3000000 );
+        $ua->max_size( $conf->{max_size} ) if $conf->{max_size};
         $ua->timeout( $conf->{timeout}   || 180 );
         $ua;
     }
diff --git a/t/tests/Test/MooseX/UserAgent.pm b/t/tests/Test/MooseX/UserAgent.pm
index 0c5a630..b63b479 100644
--- a/t/tests/Test/MooseX/UserAgent.pm
+++ b/t/tests/Test/MooseX/UserAgent.pm
@@ -17,7 +17,8 @@ use Cache::MemoryCache;
         is      => 'rw',
         default => sub {
             return {
-                name     => 'Mozilla/5.0 (compatible; LWP; RTGI; http://rtgi.fr/)',
+                name =>
+                    'Mozilla/5.0 (compatible; LWP; RTGI; http://rtgi.fr/)',
                 mail     => 'bot@rtgi.fr',
                 timeout  => 30,
                 cache    => { use_cache => 0, },
@@ -37,11 +38,11 @@ use Cache::MemoryCache;
         is      => 'rw',
         default => sub {
             return {
-                name     => 'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
-                mail     => 'bot@rtgi.fr',
-                timeout  => 30,
-                cache    => { use_cache => 0, },
-                max_size => 3000000,
+                name =>
+                    'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
+                mail    => 'bot@rtgi.fr',
+                timeout => 30,
+                cache   => { use_cache => 0, },
             };
         }
     );
@@ -75,7 +76,8 @@ sub fetch : Tests(14) {
         # test with cache
         $obj = $ua->new(
             useragent_conf => {
-                name     => 'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
+                name =>
+                    'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)',
                 cache => {
                     use_cache => 1,
                     namespace => 'testua',
@@ -86,7 +88,6 @@ sub fetch : Tests(14) {
         $res = $obj->fetch($url);
         is $res->code, "200", "... fetch is a success";
 
-        # now data should be in cache
         my $ref = $obj->ua_cache->get($url);
         ok defined $ref, "... url is now in cache";
     }
@@ -95,16 +96,37 @@ sub fetch : Tests(14) {
 sub get_content : Tests(8) {
     my $test = shift;
 
+    my $url = 'http://lumberjaph.net';
     foreach my $ua (@ua_roles) {
         can_ok $ua, 'get_content';
-
         ok my $obj = $ua->new(), ' ... object is created';
-        my $url = 'http://google.com';
         my $res = $obj->fetch($url);
-        is $res->code, "200", "... fetch is a success";
+        cmp_ok $res->code, "<", 300, "... fetch is a success";
         my $content = $obj->get_content($res);
-        like $content, qr/google/, "... and content is good";
+        like $content, qr/lumberjaph/, "... and content is good";
     }
 }
 
+sub test_cache : Tests(4) {
+    my $test = shift;
+    my $url = 'http://en.wikipedia.org';
+
+    my $obj = Test::UserAgent->new(
+        useragent_conf => { cache => { use_cache => 1 } },
+        ua_cache       => $test->cache
+        ),
+        ' ... object is created';
+    can_ok $obj, 'get_content';
+    my $res = $obj->fetch($url);
+    cmp_ok $res->code, "<", 300, "... fetch is a success";
+
+    $obj = Test::UserAgent::Async->new(
+        useragent_conf => { cache => { use_cache => 1 } },
+        ua_cache       => $test->cache
+        ),
+        ' ... object is created';
+    can_ok $obj, 'get_content';
+    $res = $obj->fetch($url);
+    is $res->code, 304, '... already in cache';
+}
 1;