From 1eecc23bbee2fc1c7f372ec5cf92d3d8c1f83abc Mon Sep 17 00:00:00 2001 From: franck cuny Date: Thu, 25 Jun 2009 15:36:19 +0200 Subject: move tests --- t/run.t | 4 ++ t/tests/Test/MooseX/UserAgent.pm | 110 ++++++++++++++++++++++++++++++++++++++ xt/run.t | 4 -- xt/tests/Test/MooseX/UserAgent.pm | 110 -------------------------------------- 4 files changed, 114 insertions(+), 114 deletions(-) create mode 100644 t/run.t create mode 100644 t/tests/Test/MooseX/UserAgent.pm delete mode 100644 xt/run.t delete mode 100644 xt/tests/Test/MooseX/UserAgent.pm diff --git a/t/run.t b/t/run.t new file mode 100644 index 0000000..30a5213 --- /dev/null +++ b/t/run.t @@ -0,0 +1,4 @@ +use lib 't/tests'; +use Test::MooseX::UserAgent; + +Test::Class->runtests; diff --git a/t/tests/Test/MooseX/UserAgent.pm b/t/tests/Test/MooseX/UserAgent.pm new file mode 100644 index 0000000..0c5a630 --- /dev/null +++ b/t/tests/Test/MooseX/UserAgent.pm @@ -0,0 +1,110 @@ +package Test::MooseX::UserAgent; + +use strict; +use warnings; +use base 'Test::Class'; +use Test::Exception; +use Test::More; +use Cache::MemoryCache; + +{ + + package Test::UserAgent; + use Moose; + with qw/MooseX::UserAgent/; + has useragent_conf => ( + isa => 'HashRef', + is => 'rw', + default => sub { + return { + name => 'Mozilla/5.0 (compatible; LWP; RTGI; http://rtgi.fr/)', + mail => 'bot@rtgi.fr', + timeout => 30, + cache => { use_cache => 0, }, + max_size => 3000000, + }; + } + ); + 1; +} +{ + + package Test::UserAgent::Async; + use Moose; + with qw/MooseX::UserAgent::Async/; + has useragent_conf => ( + isa => 'HashRef', + 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, + }; + } + ); + 1; +} + +sub cache { + my $cache = new Cache::MemoryCache( + { + 'namespace' => 'testua', + 'default_expires_in' => 600 + } + ); + return $cache; +} + +my @ua_roles = (qw/Test::UserAgent Test::UserAgent::Async/); + +sub fetch : Tests(14) { + my $test = shift; + + my $url = 'http://lumberjaph.net/blog'; + + foreach my $ua (@ua_roles) { + can_ok $ua, 'fetch'; + ok my $obj = $ua->new(), '... object is created'; + ok my $res = $obj->fetch($url), '... fetch url'; + is $res->code, "200", "... fetch is a success"; + like $res->content, qr/lumberjaph/, "... and content is good"; + + # test with cache + $obj = $ua->new( + useragent_conf => { + name => 'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)', + cache => { + use_cache => 1, + namespace => 'testua', + } + }, + ua_cache => $test->cache, + ); + $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"; + } +} + +sub get_content : Tests(8) { + my $test = shift; + + 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"; + my $content = $obj->get_content($res); + like $content, qr/google/, "... and content is good"; + } +} + +1; diff --git a/xt/run.t b/xt/run.t deleted file mode 100644 index 4f0e596..0000000 --- a/xt/run.t +++ /dev/null @@ -1,4 +0,0 @@ -use lib 'xt/tests'; -use Test::MooseX::UserAgent; - -Test::Class->runtests; diff --git a/xt/tests/Test/MooseX/UserAgent.pm b/xt/tests/Test/MooseX/UserAgent.pm deleted file mode 100644 index 0c5a630..0000000 --- a/xt/tests/Test/MooseX/UserAgent.pm +++ /dev/null @@ -1,110 +0,0 @@ -package Test::MooseX::UserAgent; - -use strict; -use warnings; -use base 'Test::Class'; -use Test::Exception; -use Test::More; -use Cache::MemoryCache; - -{ - - package Test::UserAgent; - use Moose; - with qw/MooseX::UserAgent/; - has useragent_conf => ( - isa => 'HashRef', - is => 'rw', - default => sub { - return { - name => 'Mozilla/5.0 (compatible; LWP; RTGI; http://rtgi.fr/)', - mail => 'bot@rtgi.fr', - timeout => 30, - cache => { use_cache => 0, }, - max_size => 3000000, - }; - } - ); - 1; -} -{ - - package Test::UserAgent::Async; - use Moose; - with qw/MooseX::UserAgent::Async/; - has useragent_conf => ( - isa => 'HashRef', - 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, - }; - } - ); - 1; -} - -sub cache { - my $cache = new Cache::MemoryCache( - { - 'namespace' => 'testua', - 'default_expires_in' => 600 - } - ); - return $cache; -} - -my @ua_roles = (qw/Test::UserAgent Test::UserAgent::Async/); - -sub fetch : Tests(14) { - my $test = shift; - - my $url = 'http://lumberjaph.net/blog'; - - foreach my $ua (@ua_roles) { - can_ok $ua, 'fetch'; - ok my $obj = $ua->new(), '... object is created'; - ok my $res = $obj->fetch($url), '... fetch url'; - is $res->code, "200", "... fetch is a success"; - like $res->content, qr/lumberjaph/, "... and content is good"; - - # test with cache - $obj = $ua->new( - useragent_conf => { - name => 'Mozilla/5.0 (compatible; Async; RTGI; http://rtgi.fr/)', - cache => { - use_cache => 1, - namespace => 'testua', - } - }, - ua_cache => $test->cache, - ); - $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"; - } -} - -sub get_content : Tests(8) { - my $test = shift; - - 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"; - my $content = $obj->get_content($res); - like $content, qr/google/, "... and content is good"; - } -} - -1; -- cgit v1.2.3