Paws
view release on metacpan or search on metacpan
t/13_client_connect_errors.t view on Meta::CPAN
#!/usr/bin/env perl
use Paws;
use Test::Exception;
use Test::More;
use Data::Dumper;
use Module::Runtime qw/require_module/;
use lib 't/lib';
use Test::CustomCredentials;
my $match_message_tests = $ENV{CI};
# proxies can interfere with this test, because the connection will
# succeed (to the proxy), the proxy may return some error page, so
# we're getting InvalidContent instead of ConnectionError
delete local @ENV{qw(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY)};
my $closed_server_endpoint = 'http://localhost:65511';
my $p = Paws->new(config => { credentials => 'Test::CustomCredentials' });
diag "Default caller";
throws_ok {
$p->service('EC2',
region => 'test',
region_rules => [ { uri => $closed_server_endpoint } ]
)->DescribeInstances;
} 'Paws::Exception', 'got exception';
like($@->message, qr/Connection refused|Operation timed out/, 'Correct message') if ($match_message_tests);
cmp_ok($@->code, 'eq', 'ConnectionError', 'Correct code ConnectionError code');
diag "LWP caller";
my $lwp = eval {
Paws->new(config => {
caller => 'Paws::Net::LWPCaller',
credentials => 'Test::CustomCredentials'
});
};
goto MOJO if ($@);
throws_ok {
$lwp->service('EC2',
region => 'test',
region_rules => [ { uri => $closed_server_endpoint } ]
)->DescribeInstances;
} 'Paws::Exception', 'got exception';
like($@->message, qr/Connection refused|Operation timed out/, 'Correct message') if ($match_message_tests);
cmp_ok($@->code, 'eq', 'ConnectionError', 'Correct code ConnectionError code');
MOJO:
diag "Mojo caller";
my $mojo = eval {
Paws->new(config => {
caller => 'Paws::Net::MojoAsyncCaller',
credentials => 'Test::CustomCredentials'
});
};
diag($@);
goto FURL if ($@);
throws_ok {
$mojo->service('EC2',
region => 'test',
region_rules => [ { uri => $closed_server_endpoint } ]
)->DescribeInstances->get;
} 'Paws::Exception', 'got exception';
cmp_ok($@->message, 'eq', 'Connection refused', 'Correct message') if ($match_message_tests);
cmp_ok($@->code, 'eq', 'ConnectionError', 'Correct code ConnectionError code');
FURL:
diag "Furl caller";
( run in 0.458 second using v1.01-cache-2.11-cpan-71847e10f99 )