From c24358060c208915d639ac12d1f39fbbff0c15bc Mon Sep 17 00:00:00 2001 From: franck cuny Date: Thu, 25 Jun 2009 16:27:56 +0200 Subject: add tests --- t/tests/Test/MooseX/UserAgent.pm | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 't/tests/Test') 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; -- cgit 1.4.1