Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use LWP::UserAgent; | ||
use MooseX::CachingProxy; | ||
use MooseX::Test::Role; | ||
use Test::Most; | ||
use lib 't/lib'; | ||
use t::Server; | ||
|
||
requires_ok('MooseX::CachingProxy', qw/url/); | ||
|
||
my $server = t::Server->new(); # start a web server | ||
my $uri = $server->uri . "boop"; # uri to use in tests | ||
|
||
# - create a mock object called $mock | ||
# - apply role to a $mock | ||
# - create url() and make_request() methods on $mock | ||
my $mock = consumer_of( | ||
'MooseX::CachingProxy', | ||
url => sub { $server->uri }, | ||
make_request => sub { | ||
my ($self, $uri) = @_; | ||
my $request = HTTP::Request->new(GET => $uri); | ||
return LWP::UserAgent->new()->request($request); | ||
}, | ||
); | ||
|
||
$mock->start_caching_proxy(); | ||
|
||
ok $mock->make_request($uri)->is_success, "request"; | ||
|
||
undef $server; # shut down web server | ||
|
||
ok $mock->make_request($uri)->is_success, "request from cache"; | ||
|
||
$mock->stop_caching_proxy(); | ||
|
||
ok !$mock->make_request($uri)->is_success, "request; no cache, no server"; | ||
|
||
done_testing; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package t::Server; | ||
use base 'Test::HTTP::Server'; | ||
|
||
sub Test::HTTP::Server::Request::boop { | ||
return "hey world"; | ||
} | ||
|
||
1; |