1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
use strict;
use warnings;
use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::LWP::UserAgent;
{
my $useragent = Test::LWP::UserAgent->new;
$useragent->map_response('bar.com', HTTP::Response->new('200'));
Test::LWP::UserAgent->map_response('foo.com', HTTP::Response->new('201'));
$useragent->map_response('foo.com', undef);
my $response = $useragent->get('http://foo.com');
is($response->code, '404', 'global mapping is masked on the instance');
}
{
my $useragent = Test::LWP::UserAgent->new;
$useragent->map_response('bar.com', HTTP::Response->new('200'));
$useragent->map_response('foo.com', HTTP::Response->new('201'));
$useragent->map_response('foo.com', undef);
# send request - it should hit a 404.
my $response = $useragent->get('http://foo.com');
is($response->code, '404', 'previous mapping is masked');
}
{
package MyHost;
sub new
{
my ($class, $string) = @_;
bless { _string => $string }, $class;
}
use overload '""' => sub {
my $self = shift;
$self->{_string};
};
use overload 'cmp' => sub {
my ($self, $other, $swap) = @_;
$self->{_string} cmp $other;
};
}
# same tests as above are repeated, but with overloaded string objects.
{
my $useragent = Test::LWP::UserAgent->new;
$useragent->map_response(MyHost->new('bar.com'), HTTP::Response->new('200'));
Test::LWP::UserAgent->map_response(MyHost->new('foo.com'), HTTP::Response->new('201'));
$useragent->map_response(MyHost->new('foo.com'), undef);
my $response = $useragent->get('http://foo.com');
is($response->code, '404', 'global mapping is masked on the instance');
}
{
my $useragent = Test::LWP::UserAgent->new;
$useragent->map_response(MyHost->new('bar.com'), HTTP::Response->new('200'));
$useragent->map_response(MyHost->new('foo.com'), HTTP::Response->new('201'));
$useragent->map_response(MyHost->new('foo.com'), undef);
# send request - it should hit a 404.
my $response = $useragent->get('http://foo.com');
is($response->code, '404', 'previous mapping is masked');
}
done_testing;
|